Skip to content

Instantly share code, notes, and snippets.

@Grubba27
Created April 23, 2022 03:46
Show Gist options
  • Save Grubba27/245b20973f31e62b817117f35bdde6ee to your computer and use it in GitHub Desktop.
Save Grubba27/245b20973f31e62b817117f35bdde6ee to your computer and use it in GitHub Desktop.
// 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