I am encountering an issue with a type predicate function that is designed to assign a type to a JSON object
interface Duck {
canQuack: true
}
function isDuck(duck: unknown): duck is Duck {
if (typeof duck !== "object" || ! duck) return false
return duck.canQuack === true
}
Unfortunately, TypeScript is indicating that canQuack
does not exist on object
.
Is there a way to perform a type check on an object with the unknown
type?