TS2713

error TS2713: Cannot access ‘CheckSuite.status‘ because ‘CheckSuite‘ is a type, but not a namespace. Did you mean to retrieve the type of the property ‘status‘ in ‘CheckSuite‘ with ‘CheckSuite["status"]‘?

Broken Code ❌

1
2
3
4
5
6
7
8
type CheckSuite = {
passed: boolean
status: 'ok' | 'error'
}

type ServerResponse = {
status: CheckSuite.status
}

Fixed Code ✔️

The utility type Pick comes in handy when you want to select and extract specific properties from one type and apply them to another type:

1
2
3
4
5
6
7
8
type CheckSuite = {
passed: boolean
status: 'ok' | 'error'
}

type ServerResponse = {
status: Pick<CheckSuite, 'status'>
}