Given a type T
:
type T = {
akey: string | number | undefined
}
If I check specifically for it
const fun = (p: T) => {
if(!p.akey) return
p.akey.toString()
}
Typescript understands that akey
can't be undefined.
If I do it generically though:
const fun2 = (p: T) => {
if(Object.values(p).includes(undefined)) return
p.akey.toString()
}
It does not: Object is possibly 'undefined'
.
How can I make typescript understand so I don't have to do:
p.akey!.toString()