Search This Blog

2023/09/11

Typescript:NonNullable

 type stringornumber = string | number | null | undefined


type stringornumberNoNull = NonNullable<stringornumber>
//this type will not allow null or undefined
let num:stringornumberNoNull = 56;

//this can be string ,number ,undefined or null
let num2:stringornumber = undefined

No comments:

Post a Comment