#Copy-paste of EcmaScript's Array.find interface does not work
4 messages · Page 1 of 1 (latest)
Preview:```ts
// This works as expected:
function isHelloWorld(value: unknown): value is "Hello World" {
return value === "Hello World";
}
const array2 = new Array<number | string>();
const helloWorld_2A = array2.find(isHelloWorld); // helloWorld: "Hello World" | undefined
...```
You can choose specific lines to embed by selecting them before copying the link.
Oh! Is it that I have to repeat the most generic overload (the second one) one more time to establish it as the base implementation?
find<S extends T>(predicate: (value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined;
find(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T | undefined;
// The actual implementation of the find method
find(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T | undefined
Yep, the implantation signature is purely for typechecking the implantation, it isn't visible to consumers