Skip to content

Instantly share code, notes, and snippets.

@maslade
Created March 24, 2021 23:17
Show Gist options
  • Save maslade/115f34af786674067899a568aa7cf4dd to your computer and use it in GitHub Desktop.
Save maslade/115f34af786674067899a568aa7cf4dd to your computer and use it in GitHub Desktop.
const list: Array<number | string> = [1, 'two', 3, 'four'];
// the implicit type of both of these consts is Array<string | number> -- not helpful!
const numbers = list.filter(thing => typeof thing === 'number');
const strings = list.filter(thing => typeof thing === 'string');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment