Uh oh!
There was an error while loading. Please reload this page.
feat: support error when comparing with object/array literals - #45978
Conversation
Jack-Works
commented
Sep 21, 2021

typescript-bot
commented
Sep 21, 2021
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
sandersn
commented
Sep 29, 2021
@Jack-Works please create an issue to track this. I believe @DanielRosenwasser has some experience about what issues we need to consider for adding a check like this. |
Honestly, if the thing on either side is an explicit literal, I don't think there's ever an issue with providing an error. |
Jack-Works
commented
Sep 30, 2021
Do I still need to create an issue since @DanielRosenwasser replied? |
sandersn
left a comment
There was a problem hiding this comment.
Request for one more test
(And I learned that this applies to ==, not just ===)
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Jack-Works
commented
Oct 1, 2021
What test do you want to have? Yes, it applies to if(0==false){// This condition will always return 'false' since the types 'number' and 'boolean' have no overlap.(2367)// but actually true in JavaScript} |
sandersn
commented
Oct 1, 2021
I want to test something that is (1) an existing type error (2) the new object/array literal error: constb=[1]if({a : 1}==b){}That's the only addition. |
6866a85 to
29679dfCompareJack-Works
commented
Feb 14, 2022
I have resolved the conflict, can you give another review? thanks, @sandersn@DanielRosenwasser |
29679df to
00b2084CompareJack-Works
commented
May 11, 2022
Thanks! I have rebased again to fix merge conflicts. |
sandersn
commented
May 11, 2022
Looks like a couple of tests still need their baselines updated. |
DanielRosenwasser
commented
May 13, 2022
Should we...always show this to JavaScript users? |
Jack-Works
commented
May 13, 2022
Of course, should I do anything to enable this in JavaScript? |
@Jack-Works there is a set of errors to show to JS users in src/compiler/program.ts .. plainJSErrors, I think. Add it there and it will show up for all JS users. There might be cases where |
Jack-Works
commented
May 18, 2022
There're only binder errors and grammar errors in |
sandersn
commented
May 18, 2022
Technically, yes. Grammar errors already come from the checker. I vote that we do this for 4.9, after Typescript users have had a chance to report any problems with it. In the past, JS users have gotten irate when code they know to be correct gets a TS error put on it. |
Jack-Works
commented
May 18, 2022
I can't think any case that |
It could be surfaced as a suggestion, right? I do agree that we should be a little conservative on things like this for JS users. |
Jack-Works
commented
May 19, 2022
But that's definitely a mistake even you're using JS 🤔 |
sandersn
commented
May 23, 2022
Also, suggestions ought to provide a codefix. And their default UI in vscode is extremely subtle. |
Jack-Works
commented
May 24, 2022
In this case I cannot provide a code fix because it really depends on the intension of the code 🤔 |
sandersn
commented
May 24, 2022
I think we should ship this as an error in 4.9 for JS, perhaps with some more restrictions to cut down on false positives. |
Jack-Works
commented
May 24, 2022
Can you give an example of false positives on this error? 😂 I can't think any of it |
sandersn
commented
May 24, 2022
I commented on the PR. So far they all look like intentionally bad code, so there might not be anything to do. |
bradzacher
commented
Jun 21, 2022
[1,2,3]=='1,2,3'// -> true({toString(){return1}})==1// -> true
|