typescript object type
//is not strict mode
let endedCoord: {x: number, y: number} = {
x: -1,
y: -1,
}
typescript object type
//is not strict mode
let endedCoord: {x: number, y: number} = {
x: -1,
y: -1,
}
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
typescript list
enum Color {
Red = "red",
Green = 2,
Blue = 4,
}
let c: Color = Color.Green;Try
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
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us