Last active
March 31, 2021 14:12
-
-
Save Shrugsy/4732111752f1d96da019a0f54a0a2772 to your computer and use it in GitHub Desktop.
Get a union type derived from values of a const asserted array
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
/** | |
* Get a union type derived from values of a const asserted array. | |
* @example | |
* const values = ['foo', 'bar'] as const; | |
* type Val = ArrayValues<typeof values>; | |
* // => 'foo' | 'bar' | |
* | |
* See https://github.com/microsoft/TypeScript/issues/28046#issuecomment-607145719 | |
*/ | |
export type ArrayValues<T extends ReadonlyArray<unknown>> = T[number]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Previous version: