1function stringLiterals<T extends string>(...args: T[]): T[] { return args; }
2type ElementType<T extends ReadonlyArray<unknown>> = T extends ReadonlyArray<infer ElementType> ? ElementType : never;
3
4const values = stringLiterals('A', 'B');
5type Foo = ElementType<typeof values>;
6
7const v1: Foo = 'A' // This should work
8const v2: Foo = 'D' // This should give me an error since 'D' doesn't exist in values
1const animals = ['cat', 'dog', 'mouse'] as const
2type Animal = typeof animals[number]
3
4// type Animal = 'cat' | 'dog' | 'mouse'