We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript Version: 3.9.2
Search Terms: null object unknown
Code
declare const data: unknown; if (data === null || typeof data !== 'object') { throw Error(); } data;
Expected behavior: the 'data' const should be of type object.
object
Actual behavior: the 'data' const is recognized as type object | null.
object | null
Notice that if I split the above condition into two separate if statements, then it works as expected.
if
Playground Link:
Version showcasing the bug: https://www.typescriptlang.org/play/#code/CYUwxgNghgTiAEYD2A7AzgF3sKGoC54BXFAaxSQHcUBuAKDoEsAzeAChz3gF5f4UiECPAA+I+BgCeABxBJWnKPACEfAORIARgCtwGNQEp4AbzrxzEgBYwq8AKIwbMNgfoBfBoppA
And here's the (working) version with separate if statements: https://www.typescriptlang.org/play/#code/CYUwxgNghgTiAEYD2A7AzgF3sKGoC54BXFAaxSQHcUBuAKDoEsAzeACgwE8AHEJVnHngBCALyj4AciQAjAFbgMkgJTwA3nXhb4GABYwq8AKIwDMNsvoBfBi3aCo8cRJREIEVRu079hk2YtrBgcaIA
Related Issues: none found
The text was updated successfully, but these errors were encountered:
This is a duplicate of #28131, just with the logic negated.
Sorry, something went wrong.
Right, it's the same issue.
No branches or pull requests
TypeScript Version: 3.9.2
Search Terms: null object unknown
Code
Expected behavior: the 'data' const should be of type
object
.Actual behavior: the 'data' const is recognized as type
object | null
.Notice that if I split the above condition into two separate
if
statements, then it works as expected.Playground Link:
Version showcasing the bug: https://www.typescriptlang.org/play/#code/CYUwxgNghgTiAEYD2A7AzgF3sKGoC54BXFAaxSQHcUBuAKDoEsAzeAChz3gF5f4UiECPAA+I+BgCeABxBJWnKPACEfAORIARgCtwGNQEp4AbzrxzEgBYwq8AKIwbMNgfoBfBoppA
And here's the (working) version with separate
if
statements: https://www.typescriptlang.org/play/#code/CYUwxgNghgTiAEYD2A7AzgF3sKGoC54BXFAaxSQHcUBuAKDoEsAzeACgwE8AHEJVnHngBCALyj4AciQAjAFbgMkgJTwA3nXhb4GABYwq8AKIwDMNsvoBfBi3aCo8cRJREIEVRu079hk2YtrBgcaIARelated Issues: none found
The text was updated successfully, but these errors were encountered: