Last active
April 8, 2024 16:14
-
-
Save byF/54147cae00e758b146be927821081eb3 to your computer and use it in GitHub Desktop.
more useful TS types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare global { | |
type NonFalsy<T> = T extends false | 0 | "" | null | undefined | 0n ? never : T | |
interface Array<T> { | |
filter(predicate: BooleanConstructor, thisArg?: any): NonFalsy<T>[] | |
includes<S, R extends `${Extract<S, string>}`>( | |
this: ReadonlyArray<R>, | |
searchElement: S, | |
fromIndex?: number, | |
): searchElement is R & S | |
} | |
interface ReadonlyArray<T> { | |
filter(predicate: BooleanConstructor, thisArg?: any): NonFalsy<T>[] | |
includes<S, R extends `${Extract<S, string>}`>( | |
this: ReadonlyArray<R>, | |
searchElement: S, | |
fromIndex?: number, | |
): searchElement is R & S | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment