Let say I have a constant variable
const STATUS = {
ACTIVE: "ACTIVE",
DELETED: "DELETED",
}
And I have a function which input is status
const handleStatus = (status) {
//do some thing
}
I want to define interface for status just accept 'ACTIVE' and 'DELETED' so I have to manually define like bellow
type status = 'ACTIVE' | 'DELETED'
const handleStatus = (status : status) {
//do some thing
}
Can I do something like
type status = Object.values(STATUS)
Thanks!
Edit :
I define type status = (typeof STATUS)[keyof typeof STATUS]
But when I try to check if status is valid
const validStatus = Object.values(STATUS)
if(!validStatus.includes(status)) {
//do something
}
Typescript throw error
Argument of type 'string' is not assignable to parameter of type ...