Skip to content

Instantly share code, notes, and snippets.

@jericbas
Last active November 3, 2023 09:16
Show Gist options
  • Save jericbas/9ffd6cb04e00b41409d7a664ba44f5f0 to your computer and use it in GitHub Desktop.
Save jericbas/9ffd6cb04e00b41409d7a664ba44f5f0 to your computer and use it in GitHub Desktop.
Types
const dataArray = ['A', 'B', 'C', 'D', 'E'] as const;
type data = [...(typeof dataArray)];
type Last<T extends any[]> = T extends [...infer _, infer R] ? R : never;
const last: Last<data> = 'E'
const dataArray = ['A', 'B', 'C', 'D', 'E'] as const;
type Data = typeof dataArray;
type Last<T extends readonly any[]> = T extends readonly [...infer _, infer R] ? R : never;
const last: Last<Data> = 'E';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment