Skip to content

Instantly share code, notes, and snippets.

@byF
Last active April 8, 2024 16:14
Show Gist options
  • Save byF/54147cae00e758b146be927821081eb3 to your computer and use it in GitHub Desktop.
Save byF/54147cae00e758b146be927821081eb3 to your computer and use it in GitHub Desktop.
more useful TS types
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