I know and understand what unknown
in TypeScript does. I have an untrusted input, typed as unknown
. I would like to check if it has a truthy value under input.things.0
.
function isFullOfGreatThings(input: unknown) {
return Boolean(input?.things?.[0]);
}
TypeScript complains that Object is of type 'unknown'
- however I am aware that the type is unknown, which is why I am testing for the value beneath that key.
How can I test for keys in an unknown object in TypeScript?