function isObject(v: any): v is Object{
return v instanceof Object && !Array.isArray(v);
}
let v: string | Object;
if (isObject(v))
v.hasOwnProperty("x");
else
if (typeof v === 'string')
v.trim(); //Error: Property 'trim' does not exist on type 'never'
I am confused with that error in the last line, apparently, v gets narrowed to type 'never" but I can't see the logic of it. (Typescript version 4.2.3)