arktypea
arktypeβ€’15mo ago
Stuart B

Identifying a Date value in an object type

If I iterate through an object type, I can look at each key:value and do this:
if (value.extends(type.number) { // Do some stuff 
}
if (value.extends('boolean') { // Do some different stuff 
}


How am I meant to check if a value is a Date?

I have something like this:
const schema=type(
    {
        id: 'number',
        last_updated: 'Date'
    }
)


If I iterate through the keys of a type like this looking for a Date type, I can't match it in the way I can match Boolean or number.
if (value.extends('Date')) { // some stuff 
}
if (value.extends(type('Date'))) { // some stuff 
}

Neither of these work.
Was this page helpful?