I have a function accepting user input, the argument type is unknown. I want to assert that...
valueis an objectvaluehas a key named"a"
function x(value: unknown){
if(value === null || typeof value !== 'object'){
throw new Error('Expected an object');
}
if(!('a' in value)){
throw new Error('Expected an object to contain property "a"');
}
}
Typescript complains that "Object is possibly 'null'"...
How can I narrow unknown to an object?
