Answers for "create type as values of list typescript"

3

typescript object type

//is not strict mode
let endedCoord: {x: number, y: number} = {
  	x: -1,
  	y: -1,
}
Posted by: Guest on January-05-2021
0

typescript one of array

function stringLiterals<T extends string>(...args: T[]): T[] { return args; }
type ElementType<T extends ReadonlyArray<unknown>> = T extends ReadonlyArray<infer ElementType> ? ElementType : never;

const values = stringLiterals('A', 'B');
type Foo = ElementType<typeof values>;

const v1: Foo = 'A' // This should work
const v2: Foo = 'D' // This should give me an error since 'D' doesn't exist in values
Posted by: Guest on October-08-2020
0

typescript list

enum Color {
  Red = "red",
  Green = 2,
  Blue = 4,
}
let c: Color = Color.Green;Try
Posted by: Guest on October-17-2020
0

create type as values of list typescript

// You can create your list as enums
enum statuses {
  SETUP,
  STARTED,
  FINISHED
}

// Creates known string type
// 'SETUP' | 'STARTED' | 'FINISHED'
type StatusString = keyof typeof statuses

// JobStatus.status must match 'SETUP' | 'STARTED' | 'FINISHED'
export type JobStatus = {
  status: StatusString
}
Posted by: Guest on February-08-2021

Code answers related to "create type as values of list typescript"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language