TypeScript Version: latest
Search Terms: n/a
Code
functionf(a?: {}){if(!a){// filters out falsy values:// - `null`// - `undefined`// - `false`// - `NaN`// - `0` / `-0`// - `''`return{};}// here, the type of `a` has been narrowed from "optional {}"// to just "{} minus `object`" (object-coercible, ie, anything but null/undefined, but not `object`)// effectively, this is `string | number | symbol | boolean | Function`if(typeofa!=='object'){// `a` here could be the following values:// - a function// - `true``// - a non-zero non-`NaN`` number// - a non-empty string// - a symbolreturna;// however, the type inferred here is `never`}// here, `a` has a verifiably certain type of `object`.// because of the type guard above.returna;// however, the type is reported as `{}` }Expected behavior: The type of a inside the if block will be either {}, or better, string | number | symbol | boolean | Function.
Actual behavior: The type of a inside the if block is never, which is flat out incorrect.
Playground Link:link
Related Issues: not sure how to search for it
TypeScript Version: latest
Search Terms: n/a
Code
Expected behavior: The type of
ainside theifblock will be either{}, or better,string | number | symbol | boolean | Function.Actual behavior: The type of
ainside theifblock isnever, which is flat out incorrect.Playground Link:link
Related Issues: not sure how to search for it