I have a good understanding of the unknown
type in TypeScript. I am dealing with untrusted input that is typed as unknown
, and my goal is to verify if it contains a truthy value under the key input.things.0
.
function checkGreatness(input: unknown) {
return Boolean(input?.things?.[0]);
}
Although I acknowledge that the type is 'unknown', TypeScript throws an error stating Object is of type 'unknown'
. Despite this, my intention is to validate the value associated with that specific key.
Is there a way to perform key checks on an unknown object in TypeScript?