diff --git a/dts-patches/ecmascript/Array.d.ts b/dts-patches/ecmascript/Array.d.ts index 3eb09be96..85d7ab4ad 100644 --- a/dts-patches/ecmascript/Array.d.ts +++ b/dts-patches/ecmascript/Array.d.ts @@ -53,7 +53,7 @@ * a.sort(function(a, b) { return a - b; }); // Correct numeric sort: [1, 2, 3] * ``` */ -export interface Array { +export interface Array { /** Returns true if the given object is an array, false otherwise */ static isArray(arg: any): boolean; @@ -61,62 +61,62 @@ export interface Array { length: number; /** Combines two or more arrays and returns a new array without modifying the original */ - concat(...items: any): any[]; + concat(...items: T): T[]; /** Tests whether all elements in the array pass the provided test function */ - every(callback: Java.java.util.function.Function): boolean; + every(callback: Java.java.util.function.Function): boolean; /** Creates a new array with all elements that pass the test implemented by the provided function */ - filter(callback: Java.java.util.function.Function): any[]; + filter(callback: Java.java.util.function.Function): T[]; /** Executes a provided function once for each array element. Returns undefined */ - forEach(callback: Java.java.util.function.Consumer): void; + forEach(callback: Java.java.util.function.Consumer): void; /** Returns the first index at which an element is found, or -1 if not present */ - indexOf(searchElement: any, fromIndex: number): number; + indexOf(searchElement: T, fromIndex: number): number; /** Joins all elements of an array into a string separated by the given separator */ join(separator: string): string; /** Returns the last index at which an element is found, or -1 if not present */ - lastIndexOf(searchElement: any, fromIndex: number): number; + lastIndexOf(searchElement: T, fromIndex: number): number; /** Creates a new array with the results of calling a function on every element */ - map(callback: Java.java.util.function.Function): any[]; + map(callback: Java.java.util.function.Function): any[]; /** Removes and returns the last element from the array, modifying the original array */ - pop(): any; + pop(): T; /** Adds one or more elements to the end of an array and returns the new length */ - push(...items: any): number; + push(...items: T): number; /** Applies a function against an accumulator and each element to reduce the array to a single value */ - reduce(callback: Java.java.util.function.BiFunction, initialValue: any): any; + reduce(callback: Java.java.util.function.BiFunction, initialValue: any): any; /** Same as reduce() but processes the array from right to left */ - reduceRight(callback: Java.java.util.function.BiFunction, initialValue: any): any; + reduceRight(callback: Java.java.util.function.BiFunction, initialValue: any): any; /** Reverses an array in place. The first element becomes the last, and vice versa */ - reverse(): any[]; + reverse(): T[]; /** Removes and returns the first element from the array, modifying the original array */ - shift(): any; + shift(): T; /** Returns a shallow copy of a portion of an array as a new array object */ - slice(start: number, end: number): any[]; + slice(start: number, end: number): T[]; /** Tests whether at least one element in the array passes the test implemented by the provided function */ - some(callback: Java.java.util.function.Function): boolean; + some(callback: Java.java.util.function.Function): boolean; /** Sorts the elements of an array in place and returns the sorted array */ - sort(compareFn: Java.java.util.function.BiFunction): any[]; + sort(compareFn: Java.java.util.function.BiFunction): T[]; /** Changes the contents of an array by removing or replacing existing elements and/or adding new ones */ - splice(start: number, deleteCount: number, ...items: any): any[]; + splice(start: number, deleteCount: number, ...items: T): T[]; /** Returns a string representation of the array */ toString(): string; /** Adds one or more elements to the beginning of an array and returns the new length */ - unshift(...items: any): number; + unshift(...items: T): number; } diff --git a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/type/GenericContext.java b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/type/GenericContext.java index 1d1162ac9..916623586 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/type/GenericContext.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/type/GenericContext.java @@ -49,6 +49,13 @@ public final class GenericContext { * @return a context with applied bindings and bound fallbacks, or EMPTY singleton if receiverType is not generic */ public static GenericContext forReceiver(TypeInfo receiverType) { + // Special edge case: Array.d.ts JS type, bind T to element type so Array methods resolve correctly + if (receiverType != null && receiverType.isArray() && receiverType.getElementType() != null) { + Map applied = new HashMap<>(); + applied.put("T", receiverType.getElementType()); + return new GenericContext(applied, new HashMap<>()); + } + // Fast path: return singleton for non-generic types if (receiverType == null || !hasGenerics(receiverType)) { return EMPTY;