typescript define types any code example
Example 1: typescript object type
//is not strict mode
let endedCoord: {x: number, y: number} = {
x: -1,
y: -1,
}
Example 2: 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
}