-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Assert functions do not constraint type when they are guarded by a truthy expression. #37295
New issue
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
Comments
…asserts As of TypeScript 3.7, TypeScript supports [Assert Functions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions). This change adds assert types to our `assert*` functions. We can't fully take advantage of this due to [Assert functions do not constraint type when they are guarded by a truthy expression.](microsoft/TypeScript#37295)
…asserts (#35964) As of TypeScript 3.7, TypeScript supports [Assert Functions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions). This change adds assert types to our `assert*` functions. We can't fully take advantage of this due to [Assert functions do not constraint type when they are guarded by a truthy expression.](microsoft/TypeScript#37295) PR Close #35964
…asserts (#35964) As of TypeScript 3.7, TypeScript supports [Assert Functions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions). This change adds assert types to our `assert*` functions. We can't fully take advantage of this due to [Assert functions do not constraint type when they are guarded by a truthy expression.](microsoft/TypeScript#37295) PR Close #35964
We don't trust the results of our own truthiness analysis for these situations because there are legitimate situations where a falsy value might inhabit a truthy position. We also believe that code like |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version: 3.8.3
Search Terms:: Assert Function
Code
Expected behavior:
Assert functions should be assumed to always execute when they are guarded by an expression which is truthy.
Actual behavior:
Any sort of guard expression (even if know to be truthy) prevents the assert function from applying its constraint.
Playground Link:
Playground
Related Issues:
The text was updated successfully, but these errors were encountered: