Created
April 23, 2022 03:46
-
-
Save Grubba27/245b20973f31e62b817117f35bdde6ee to your computer and use it in GitHub Desktop.
Enumerated Types as https://softwarefoundations.cis.upenn.edu/lf-current/Basics.html
This file contains 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
// https://softwarefoundations.cis.upenn.edu/lf-current/Basics.html | |
type Last<T extends any[]> = T extends [...infer R,infer L] ? L : never; | |
type D = ['Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado', 'Domingo'] | |
type DProx | |
<I = D, R = {}, H extends any = ''> = | |
I extends [infer Head, infer Next, ...infer Tail] | |
? DProx<[Next, ...Tail], R & Record<Head, Next> & Record<Last<D>, D[0]>> | |
: { [K in keyof R]: R[K] } | |
const d : DProx['Domingo'] = 'Segunda' | |
const d : DProx['Terça'] = 'Quarta' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment