1//is not strict mode
2let endedCoord: {x: number, y: number} = {
3 x: -1,
4 y: -1,
5}
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
1enum Color {
2 Red = "red",
3 Green = 2,
4 Blue = 4,
5}
6let c: Color = Color.Green;Try
1// You can create your list as enums
2enum statuses {
3 SETUP,
4 STARTED,
5 FINISHED
6}
7
8// Creates known string type
9// 'SETUP' | 'STARTED' | 'FINISHED'
10type StatusString = keyof typeof statuses
11
12// JobStatus.status must match 'SETUP' | 'STARTED' | 'FINISHED'
13export type JobStatus = {
14 status: StatusString
15}
16