-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Disallow truthiness/nullishness checks on syntax that never varies on it #59217
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
Changes from 8 commits
26f7cd3
263a967
02353fc
f4a4251
ca1034f
701b54a
3388e4c
6d0da7a
64d27ce
f988a05
b786cf2
5f59624
ba53157
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -923,6 +923,14 @@ export const enum RelationComparisonResult { | |
| Overflow = ComplexityOverflow | StackDepthOverflow, | ||
| } | ||
|
|
||
| /** @internal */ | ||
| export const enum PredicateSemantics { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
| None = 0, | ||
| Always = 1 << 0, | ||
| Never = 1 << 1, | ||
| Sometimes = Always | Never, | ||
| } | ||
|
|
||
| /** @internal */ | ||
| export type NodeId = number; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| returns.js(20,12): error TS2872: This kind of expression is always truthy. | ||
|
|
||
|
|
||
| ==== returns.js (1 errors) ==== | ||
| // @ts-check | ||
| /** | ||
| * @returns {string} This comment is not currently exposed | ||
| */ | ||
| function f() { | ||
| return "hello"; | ||
| } | ||
|
|
||
| /** | ||
| * @returns {string=} This comment is not currently exposed | ||
| */ | ||
| function f1() { | ||
| return "hello world"; | ||
| } | ||
|
|
||
| /** | ||
| * @returns {string|number} This comment is not currently exposed | ||
| */ | ||
| function f2() { | ||
| return 5 || "hello"; | ||
| ~ | ||
| !!! error TS2872: This kind of expression is always truthy. | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| computedPropertyNames46_ES5.ts(2,6): error TS2873: This kind of expression is always falsy. | ||
|
|
||
|
|
||
| ==== computedPropertyNames46_ES5.ts (1 errors) ==== | ||
| var o = { | ||
| ["" || 0]: 0 | ||
| ~~ | ||
| !!! error TS2873: This kind of expression is always falsy. | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| computedPropertyNames46_ES6.ts(2,6): error TS2873: This kind of expression is always falsy. | ||
|
|
||
|
|
||
| ==== computedPropertyNames46_ES6.ts (1 errors) ==== | ||
| var o = { | ||
| ["" || 0]: 0 | ||
| ~~ | ||
| !!! error TS2873: This kind of expression is always falsy. | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| computedPropertyNames48_ES5.ts(16,6): error TS2873: This kind of expression is always falsy. | ||
|
|
||
|
|
||
| ==== computedPropertyNames48_ES5.ts (1 errors) ==== | ||
| declare function extractIndexer<T>(p: { [n: number]: T }): T; | ||
|
|
||
| enum E { x } | ||
|
|
||
| var a: any; | ||
|
|
||
| extractIndexer({ | ||
| [a]: "" | ||
| }); // Should return string | ||
|
|
||
| extractIndexer({ | ||
| [E.x]: "" | ||
| }); // Should return string | ||
|
|
||
| extractIndexer({ | ||
| ["" || 0]: "" | ||
| ~~ | ||
| !!! error TS2873: This kind of expression is always falsy. | ||
| }); // Should return any (widened form of undefined) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ enum E { x } | |
|
|
||
| var a: any; | ||
| >a : any | ||
| > : ^^^ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happened that updated the types baselines like this?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a goofy quirk of the types baselines; in // Distinguish `errorType`s from `any`s; but only if the file has no errors.So this types file changed because
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Honestly, I wonder if it's worth the special case; I noticed it separately while working on something else) |
||
|
|
||
| extractIndexer({ | ||
| >extractIndexer({ [a]: ""}) : string | ||
|
|
@@ -30,6 +31,7 @@ extractIndexer({ | |
| >[a] : string | ||
| > : ^^^^^^ | ||
| >a : any | ||
| > : ^^^ | ||
| >"" : "" | ||
| > : ^^ | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| computedPropertyNames48_ES6.ts(16,6): error TS2873: This kind of expression is always falsy. | ||
|
|
||
|
|
||
| ==== computedPropertyNames48_ES6.ts (1 errors) ==== | ||
| declare function extractIndexer<T>(p: { [n: number]: T }): T; | ||
|
|
||
| enum E { x } | ||
|
|
||
| var a: any; | ||
|
|
||
| extractIndexer({ | ||
| [a]: "" | ||
| }); // Should return string | ||
|
|
||
| extractIndexer({ | ||
| [E.x]: "" | ||
| }); // Should return string | ||
|
|
||
| extractIndexer({ | ||
| ["" || 0]: "" | ||
| ~~ | ||
| !!! error TS2873: This kind of expression is always falsy. | ||
| }); // Should return any (widened form of undefined) |
Uh oh!
There was an error while loading. Please reload this page.