Skip to content

Commit 9422555

Browse files
committed
move BinaryExpression case to the checker too
1 parent 5daf0c0 commit 9422555

13 files changed

+50
-54
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31565,6 +31565,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3156531565
case SyntaxKind.AmpersandAmpersandToken:
3156631566
case SyntaxKind.CommaToken:
3156731567
return node === right ? getContextualType(binaryExpression, contextFlags) : undefined;
31568+
case SyntaxKind.EqualsEqualsEqualsToken:
31569+
case SyntaxKind.EqualsEqualsToken:
31570+
case SyntaxKind.ExclamationEqualsEqualsToken:
31571+
case SyntaxKind.ExclamationEqualsToken:
31572+
return getTypeOfExpression(node === right ? left : right);
3156831573
default:
3156931574
return undefined;
3157031575
}

src/compiler/utilities.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11896,12 +11896,6 @@ export function isEqualityOperatorKind(kind: SyntaxKind): kind is EqualityOperat
1189611896
export function getContextualTypeFromParent(node: Expression, checker: TypeChecker, contextFlags?: ContextFlags): Type | undefined {
1189711897
const parent = walkUpParenthesizedExpressions(node.parent);
1189811898
switch (parent.kind) {
11899-
case SyntaxKind.BinaryExpression: {
11900-
const { left, operatorToken, right } = parent as BinaryExpression;
11901-
return isEqualityOperatorKind(operatorToken.kind)
11902-
? checker.getTypeAtLocation(node === right ? left : right)
11903-
: checker.getContextualType(node, contextFlags);
11904-
}
1190511899
case SyntaxKind.CaseClause:
1190611900
return checker.getTypeAtLocation((parent as CaseClause).parent.parent.expression);
1190711901
default:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
compareTypeParameterConstrainedByLiteralToLiteral.ts(5,5): error TS2367: This comparison appears to be unintentional because the types 'T' and '"x"' have no overlap.
1+
compareTypeParameterConstrainedByLiteralToLiteral.ts(5,5): error TS2367: This comparison appears to be unintentional because the types '"a" | "b"' and '"x"' have no overlap.
22

33

44
==== compareTypeParameterConstrainedByLiteralToLiteral.ts (1 errors) ====
@@ -8,6 +8,6 @@ compareTypeParameterConstrainedByLiteralToLiteral.ts(5,5): error TS2367: This co
88
t === "a"; // Should be allowed
99
t === "x"; // Should be error
1010
~~~~~~~~~
11-
!!! error TS2367: This comparison appears to be unintentional because the types 'T' and '"x"' have no overlap.
11+
!!! error TS2367: This comparison appears to be unintentional because the types '"a" | "b"' and '"x"' have no overlap.
1212
}
1313

tests/baselines/reference/compareTypeParameterConstrainedByLiteralToLiteral.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ function foo<T extends "a" | "b">(t: T) {
1212
t === "a"; // Should be allowed
1313
>t === "a" : boolean
1414
> : ^^^^^^^
15-
>t : T
16-
> : ^
15+
>t : "a" | "b"
16+
> : ^^^^^^^^^
1717
>"a" : "a"
1818
> : ^^^
1919

2020
t === "x"; // Should be error
2121
>t === "x" : boolean
2222
> : ^^^^^^^
23-
>t : T
24-
> : ^
23+
>t : "a" | "b"
24+
> : ^^^^^^^^^
2525
>"x" : "x"
2626
> : ^^^
2727
}

tests/baselines/reference/controlFlowGenericTypes.types

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ export function bounceAndTakeIfA<AB extends 'A' | 'B'>(value: AB): AB {
266266
if (value === 'A') {
267267
>value === 'A' : boolean
268268
> : ^^^^^^^
269-
>value : AB
270-
> : ^^
269+
>value : "A" | "B"
270+
> : ^^^^^^^^^
271271
>'A' : "A"
272272
> : ^^^
273273

@@ -517,8 +517,8 @@ function get<K extends keyof A>(key: K, obj: A): number {
517517
if (value !== null) {
518518
>value !== null : boolean
519519
> : ^^^^^^^
520-
>value : A[K]
521-
> : ^^^^
520+
>value : number | null
521+
> : ^^^^^^^^^^^^^
522522

523523
return value;
524524
>value : number
@@ -729,8 +729,8 @@ class TableBaseEnum<
729729
if (iSpec === undefined) {
730730
>iSpec === undefined : boolean
731731
> : ^^^^^^^
732-
>iSpec : InternalSpec
733-
> : ^^^^^^^^^^^^
732+
>iSpec : Record<keyof PublicSpec, any> | undefined
733+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
734734
>undefined : undefined
735735
> : ^^^^^^^^^
736736

@@ -852,8 +852,8 @@ function update<T extends Control, K extends keyof T>(control : T | undefined, k
852852
if (control !== undefined) {
853853
>control !== undefined : boolean
854854
> : ^^^^^^^
855-
>control : T | undefined
856-
> : ^^^^^^^^^^^^^
855+
>control : Control | undefined
856+
> : ^^^^^^^^^^^^^^^^^^^
857857
>undefined : undefined
858858
> : ^^^^^^^^^
859859

tests/baselines/reference/intersectionNarrowing.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
intersectionNarrowing.ts(36,16): error TS2367: This comparison appears to be unintentional because the types 'T & number' and 'string' have no overlap.
1+
intersectionNarrowing.ts(36,16): error TS2367: This comparison appears to be unintentional because the types 'number' and 'string' have no overlap.
22

33

44
==== intersectionNarrowing.ts (1 errors) ====
@@ -39,6 +39,6 @@ intersectionNarrowing.ts(36,16): error TS2367: This comparison appears to be uni
3939
function f5<T extends string | number>(x: T & number) {
4040
const t1 = x === "hello"; // Should be an error
4141
~~~~~~~~~~~~~
42-
!!! error TS2367: This comparison appears to be unintentional because the types 'T & number' and 'string' have no overlap.
42+
!!! error TS2367: This comparison appears to be unintentional because the types 'number' and 'string' have no overlap.
4343
}
4444

tests/baselines/reference/intersectionNarrowing.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ function f5<T extends string | number>(x: T & number) {
110110
> : ^^^^^^^
111111
>x === "hello" : boolean
112112
> : ^^^^^^^
113-
>x : T & number
114-
> : ^^^^^^^^^^
113+
>x : number
114+
> : ^^^^^^
115115
>"hello" : "hello"
116116
> : ^^^^^^^
117117
}

tests/baselines/reference/intersectionsOfLargeUnions.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ export function assertNodeTagName<
7878
> : ^^^^^^^
7979
>nodeTagName : string
8080
> : ^^^^^^
81-
>tagName : T
82-
> : ^
81+
>tagName : "symbol" | "animate" | "animateMotion" | "animateTransform" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "filter" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "set" | "stop" | "svg" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | keyof HTMLElementTagNameMap
82+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8383
}
8484
return false;
8585
>false : false

tests/baselines/reference/intersectionsOfLargeUnions2.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ export function assertNodeTagName<
9595
> : ^^^^^^^
9696
>nodeTagName : string
9797
> : ^^^^^^
98-
>tagName : T
99-
> : ^
98+
>tagName : "symbol" | "animate" | "animateMotion" | "animateTransform" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "filter" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "set" | "stop" | "svg" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | keyof HTMLElementTagNameMap
99+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
100100
}
101101
return false;
102102
>false : false

tests/baselines/reference/recursiveTypeRelations.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNam
6666
if (arg == null) {
6767
>arg == null : boolean
6868
> : ^^^^^^^
69-
>arg : ClassNameArg<S>
70-
> : ^^^^^^^^^^^^^^^
69+
>arg : string | number | symbol | ClassNameObjectMap<S>
70+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7171

7272
return null;
7373
}

tests/baselines/reference/trackedSymbolsNoCrash.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ export const isNodeOfType =
10541054
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
10551055
>kind : ast.SyntaxKind | undefined
10561056
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
1057-
>nodeType : NodeType
1058-
> : ^^^^^^^^
1057+
>nodeType : ast.SyntaxKind
1058+
> : ^^^^^^^^^^^^^^
10591059

10601060

tests/baselines/reference/unknownControlFlow.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ unknownControlFlow.ts(290,11): error TS2345: Argument of type 'string' is not as
44
unknownControlFlow.ts(291,5): error TS2345: Argument of type 'null' is not assignable to parameter of type 'never'.
55
unknownControlFlow.ts(293,5): error TS2345: Argument of type 'null' is not assignable to parameter of type 'never'.
66
unknownControlFlow.ts(323,9): error TS2367: This comparison appears to be unintentional because the types 'T' and 'number' have no overlap.
7-
unknownControlFlow.ts(341,9): error TS2367: This comparison appears to be unintentional because the types 'T' and 'number' have no overlap.
87

98

10-
==== unknownControlFlow.ts (7 errors) ====
9+
==== unknownControlFlow.ts (6 errors) ====
1110
type T01 = {} & string; // {} & string
1211
type T02 = {} & 'a'; // 'a'
1312
type T03 = {} & object; // object
@@ -361,8 +360,6 @@ unknownControlFlow.ts(341,9): error TS2367: This comparison appears to be uninte
361360

362361
function fx4<T extends {} | null>(value: T & ({} | null)) {
363362
if (value === 42) {
364-
~~~~~~~~~~~~
365-
!!! error TS2367: This comparison appears to be unintentional because the types 'T' and 'number' have no overlap.
366363
value; // T & {}
367364
}
368365
else {

tests/baselines/reference/unknownControlFlow.types

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ function f22<T extends {} | undefined>(x: T) {
380380
if (x !== undefined) {
381381
>x !== undefined : boolean
382382
> : ^^^^^^^
383-
>x : T
384-
> : ^
383+
>x : {} | undefined
384+
> : ^^^^^^^^^^^^^^
385385
>undefined : undefined
386386
> : ^^^^^^^^^
387387

@@ -397,8 +397,8 @@ function f22<T extends {} | undefined>(x: T) {
397397
if (x !== null) {
398398
>x !== null : boolean
399399
> : ^^^^^^^
400-
>x : T
401-
> : ^
400+
>x : {} | undefined
401+
> : ^^^^^^^^^^^^^^
402402

403403
x; // T
404404
>x : T
@@ -414,14 +414,14 @@ function f22<T extends {} | undefined>(x: T) {
414414
> : ^^^^^^^
415415
>x !== undefined : boolean
416416
> : ^^^^^^^
417-
>x : T
418-
> : ^
417+
>x : {} | undefined
418+
> : ^^^^^^^^^^^^^^
419419
>undefined : undefined
420420
> : ^^^^^^^^^
421421
>x !== null : boolean
422422
> : ^^^^^^^
423-
>x : T & {}
424-
> : ^^^^^^
423+
>x : {}
424+
> : ^^
425425

426426
x; // T & {}
427427
>x : T & {}
@@ -435,8 +435,8 @@ function f22<T extends {} | undefined>(x: T) {
435435
if (x != undefined) {
436436
>x != undefined : boolean
437437
> : ^^^^^^^
438-
>x : T
439-
> : ^
438+
>x : {} | undefined
439+
> : ^^^^^^^^^^^^^^
440440
>undefined : undefined
441441
> : ^^^^^^^^^
442442

@@ -452,8 +452,8 @@ function f22<T extends {} | undefined>(x: T) {
452452
if (x != null) {
453453
>x != null : boolean
454454
> : ^^^^^^^
455-
>x : T
456-
> : ^
455+
>x : {} | undefined
456+
> : ^^^^^^^^^^^^^^
457457

458458
x; // T & {}
459459
>x : NonNullable<T>
@@ -1255,8 +1255,8 @@ function fx3<T extends {} | undefined>(value: T & ({} | null)) {
12551255
if (value === 42) {
12561256
>value === 42 : boolean
12571257
> : ^^^^^^^
1258-
>value : T & {}
1259-
> : ^^^^^^
1258+
>value : {}
1259+
> : ^^
12601260
>42 : 42
12611261
> : ^^
12621262

@@ -1280,8 +1280,8 @@ function fx4<T extends {} | null>(value: T & ({} | null)) {
12801280
if (value === 42) {
12811281
>value === 42 : boolean
12821282
> : ^^^^^^^
1283-
>value : T
1284-
> : ^
1283+
>value : {} | null
1284+
> : ^^^^^^^^^
12851285
>42 : 42
12861286
> : ^^
12871287

@@ -1305,8 +1305,8 @@ function fx5<T extends {} | null | undefined>(value: T & ({} | null)) {
13051305
if (value === 42) {
13061306
>value === 42 : boolean
13071307
> : ^^^^^^^
1308-
>value : T & ({} | null)
1309-
> : ^^^^^^^^^^^^^^^
1308+
>value : {} | null
1309+
> : ^^^^^^^^^
13101310
>42 : 42
13111311
> : ^^
13121312

0 commit comments

Comments
 (0)