Skip to content

Commit 7f82beb

Browse files
committed
Merge pull request #8443 from Microsoft/controlFlowAccessors
Include accessors in control flow type analysis
2 parents 2c4946f + c44fe76 commit 7f82beb

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9795,7 +9795,7 @@ namespace ts {
97959795
}
97969796

97979797
const propType = getTypeOfSymbol(prop);
9798-
if (node.kind !== SyntaxKind.PropertyAccessExpression || !(prop.flags & (SymbolFlags.Variable | SymbolFlags.Property)) || isAssignmentTarget(node)) {
9798+
if (node.kind !== SyntaxKind.PropertyAccessExpression || !(prop.flags & (SymbolFlags.Variable | SymbolFlags.Property | SymbolFlags.Accessor)) || isAssignmentTarget(node)) {
97999799
return propType;
98009800
}
98019801
const leftmostNode = getLeftmostIdentifierOrThis(node);

tests/baselines/reference/typeGuardsInProperties.types

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ class C1 {
5757
>pp2 : string
5858

5959
strOrNum = typeof this.pp3 === "string" && this.pp3; // string | number
60-
>strOrNum = typeof this.pp3 === "string" && this.pp3 : string | number
60+
>strOrNum = typeof this.pp3 === "string" && this.pp3 : string
6161
>strOrNum : string | number
62-
>typeof this.pp3 === "string" && this.pp3 : string | number
62+
>typeof this.pp3 === "string" && this.pp3 : string
6363
>typeof this.pp3 === "string" : boolean
6464
>typeof this.pp3 : string
6565
>this.pp3 : string | number
6666
>this : this
6767
>pp3 : string | number
6868
>"string" : string
69-
>this.pp3 : string | number
69+
>this.pp3 : string
7070
>this : this
71-
>pp3 : string | number
71+
>pp3 : string
7272
}
7373
}
7474
var c1: C1;
@@ -90,18 +90,18 @@ strOrNum = typeof c1.pp2 === "string" && c1.pp2; // string | number
9090
>pp2 : string
9191

9292
strOrNum = typeof c1.pp3 === "string" && c1.pp3; // string | number
93-
>strOrNum = typeof c1.pp3 === "string" && c1.pp3 : string | number
93+
>strOrNum = typeof c1.pp3 === "string" && c1.pp3 : string
9494
>strOrNum : string | number
95-
>typeof c1.pp3 === "string" && c1.pp3 : string | number
95+
>typeof c1.pp3 === "string" && c1.pp3 : string
9696
>typeof c1.pp3 === "string" : boolean
9797
>typeof c1.pp3 : string
9898
>c1.pp3 : string | number
9999
>c1 : C1
100100
>pp3 : string | number
101101
>"string" : string
102-
>c1.pp3 : string | number
102+
>c1.pp3 : string
103103
>c1 : C1
104-
>pp3 : string | number
104+
>pp3 : string
105105

106106
var obj1: {
107107
>obj1 : { x: string | number; }

tests/baselines/reference/typeGuardsObjectMethods.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,16 @@ strOrNum = typeof obj1.method(strOrNum) === "string" && obj1.method(strOrNum);
172172

173173
// accessing getter property
174174
strOrNum = typeof obj1.prop === "string" && obj1.prop;
175-
>strOrNum = typeof obj1.prop === "string" && obj1.prop : string | number
175+
>strOrNum = typeof obj1.prop === "string" && obj1.prop : string
176176
>strOrNum : string | number
177-
>typeof obj1.prop === "string" && obj1.prop : string | number
177+
>typeof obj1.prop === "string" && obj1.prop : string
178178
>typeof obj1.prop === "string" : boolean
179179
>typeof obj1.prop : string
180180
>obj1.prop : string | number
181181
>obj1 : { method(param: string | number): string | number; prop: string | number; }
182182
>prop : string | number
183183
>"string" : string
184-
>obj1.prop : string | number
184+
>obj1.prop : string
185185
>obj1 : { method(param: string | number): string | number; prop: string | number; }
186-
>prop : string | number
186+
>prop : string
187187

0 commit comments

Comments
 (0)