Skip to content

Instantly share code, notes, and snippets.

@lmcarreiro
Created March 30, 2018 02:23
Show Gist options
  • Save lmcarreiro/8e14f9af3e66793d0e81d64a5d29e739 to your computer and use it in GitHub Desktop.
Save lmcarreiro/8e14f9af3e66793d0e81d64a5d29e739 to your computer and use it in GitHub Desktop.
filter function overload broken into multiple lines
export function filter<T, U extends T>(
array: T[],
f: (x: T) => x is U
) : U[];
export function filter<T>(
array: T[],
f: (x: T) => boolean
) : T[];
export function filter<T, U extends T>(
array: ReadonlyArray<T>,
f: (x: T) => x is U
): ReadonlyArray<U>;
export function filter<T, U extends T>(
array: ReadonlyArray<T>,
f: (x: T) => boolean
): ReadonlyArray<T>;
export function filter<T>(
array: T[],
f: (x: T) => boolean
): T[] {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment