Created
June 13, 2020 00:25
-
-
Save karol-majewski/6c3f6273d377a42f728488c1a337f479 to your computer and use it in GitHub Desktop.
Array.prototype.match overload that works for tuples
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
// 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