Skip to content

Instantly share code, notes, and snippets.

@karol-majewski
Created June 13, 2020 00:25
Show Gist options
  • Save karol-majewski/6c3f6273d377a42f728488c1a337f479 to your computer and use it in GitHub Desktop.
Save karol-majewski/6c3f6273d377a42f728488c1a337f479 to your computer and use it in GitHub Desktop.
Array.prototype.match overload that works for tuples
// 1. Let's define a tuple of country codes.
const countries: [string, string] = ["es", "ko"];
// 2. Good! We know the returned tuple will only have two elements.
const [spanish, korean, valyrian] =
countries.map(country => new Intl.DateTimeFormat(country));
// 3. We know `valyrian` doesn't exist!
valyrian.format(new Date());
declare global {
interface Array<T> {
map<U>(this: T[] | [T], callbackfn: (value: T, index: number, array: this) => U, thisArg?: any): {
[index in keyof this]: U
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment