Skip to content

Instantly share code, notes, and snippets.

@lafiosca
Created January 17, 2020 00:36
Show Gist options
  • Save lafiosca/5020ecc4388c3feb60e4a0e7eb410918 to your computer and use it in GitHub Desktop.
Save lafiosca/5020ecc4388c3feb60e4a0e7eb410918 to your computer and use it in GitHub Desktop.
Inconsistent type inference of object or null
const foo = (x: unknown) => { // function(x: unknown): object | null
if (x === null || typeof x !== 'object') {
throw Error();
}
return x;
};
const bar = (x: unknown) => { // function(x: unknown): object
if (typeof x !== 'object' || x === null) {
throw Error();
}
return x;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment