-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Error on syntactically impossible ===s to undefined #60433
Draft
RyanCavanaugh
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
RyanCavanaugh:fix60425
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
tests/baselines/reference/conditionalOperatorConditionIsBooleanType.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
conditionalOperatorConditionIsBooleanType.ts(36,1): error TS2870: This binary expression is never nullish. Are you missing parentheses? | ||
conditionalOperatorConditionIsBooleanType.ts(38,1): error TS2870: This binary expression is never nullish. Are you missing parentheses? | ||
conditionalOperatorConditionIsBooleanType.ts(59,23): error TS2870: This binary expression is never nullish. Are you missing parentheses? | ||
|
||
|
||
==== conditionalOperatorConditionIsBooleanType.ts (3 errors) ==== | ||
//Cond ? Expr1 : Expr2, Cond is of boolean type, Expr1 and Expr2 have the same type | ||
var condBoolean: boolean; | ||
|
||
var exprAny1: any; | ||
var exprBoolean1: boolean; | ||
var exprNumber1: number; | ||
var exprString1: string; | ||
var exprIsObject1: Object; | ||
|
||
var exprAny2: any; | ||
var exprBoolean2: boolean; | ||
var exprNumber2: number; | ||
var exprString2: string; | ||
var exprIsObject2: Object; | ||
|
||
//Cond is a boolean type variable | ||
condBoolean ? exprAny1 : exprAny2; | ||
condBoolean ? exprBoolean1 : exprBoolean2; | ||
condBoolean ? exprNumber1 : exprNumber2; | ||
condBoolean ? exprString1 : exprString2; | ||
condBoolean ? exprIsObject1 : exprIsObject2; | ||
condBoolean ? exprString1 : exprBoolean1; // union | ||
|
||
//Cond is a boolean type literal | ||
true ? exprAny1 : exprAny2; | ||
false ? exprBoolean1 : exprBoolean2; | ||
true ? exprNumber1 : exprNumber2; | ||
false ? exprString1 : exprString2; | ||
true ? exprIsObject1 : exprIsObject2; | ||
true ? exprString1 : exprBoolean1; // union | ||
|
||
//Cond is a boolean type expression | ||
!true ? exprAny1 : exprAny2; | ||
typeof "123" == "string" ? exprBoolean1 : exprBoolean2; | ||
2 > 1 ? exprNumber1 : exprNumber2; | ||
null === undefined ? exprString1 : exprString2; | ||
~~~~ | ||
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses? | ||
true || false ? exprIsObject1 : exprIsObject2; | ||
null === undefined ? exprString1 : exprBoolean1; // union | ||
~~~~ | ||
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses? | ||
|
||
//Results shoud be same as Expr1 and Expr2 | ||
var resultIsAny1 = condBoolean ? exprAny1 : exprAny2; | ||
var resultIsBoolean1 = condBoolean ? exprBoolean1 : exprBoolean2; | ||
var resultIsNumber1 = condBoolean ? exprNumber1 : exprNumber2; | ||
var resultIsString1 = condBoolean ? exprString1 : exprString2; | ||
var resultIsObject1 = condBoolean ? exprIsObject1 : exprIsObject2; | ||
var resultIsStringOrBoolean1 = condBoolean ? exprString1 : exprBoolean1; // union | ||
|
||
var resultIsAny2 = true ? exprAny1 : exprAny2; | ||
var resultIsBoolean2 = false ? exprBoolean1 : exprBoolean2; | ||
var resultIsNumber2 = true ? exprNumber1 : exprNumber2; | ||
var resultIsString2 = false ? exprString1 : exprString2; | ||
var resultIsObject2 = true ? exprIsObject1 : exprIsObject2; | ||
var resultIsStringOrBoolean2 = true ? exprString1 : exprBoolean1; // union | ||
var resultIsStringOrBoolean3 = false ? exprString1 : exprBoolean1; // union | ||
|
||
var resultIsAny3 = !true ? exprAny1 : exprAny2; | ||
var resultIsBoolean3 = typeof "123" == "string" ? exprBoolean1 : exprBoolean2; | ||
var resultIsNumber3 = 2 > 1 ? exprNumber1 : exprNumber2; | ||
var resultIsString3 = null === undefined ? exprString1 : exprString2; | ||
~~~~ | ||
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses? | ||
var resultIsObject3 = true || false ? exprIsObject1 : exprIsObject2; | ||
var resultIsStringOrBoolean4 = typeof "123" === "string" ? exprString1 : exprBoolean1; // union | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we get this error here? Surely
undefined
is always nullish?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i mean, when it's not ES5, or not the global scope, it could be any value, but presumably TS is ignoring that possibility :-)