Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9795,7 +9795,7 @@ namespace ts {
}

const propType = getTypeOfSymbol(prop);
if (node.kind !== SyntaxKind.PropertyAccessExpression || !(prop.flags & (SymbolFlags.Variable | SymbolFlags.Property)) || isAssignmentTarget(node)) {
if (node.kind !== SyntaxKind.PropertyAccessExpression || !(prop.flags & (SymbolFlags.Variable | SymbolFlags.Property | SymbolFlags.Accessor)) || isAssignmentTarget(node)) {
return propType;
}
const leftmostNode = getLeftmostIdentifierOrThis(node);
Expand Down
16 changes: 8 additions & 8 deletions tests/baselines/reference/typeGuardsInProperties.types
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ class C1 {
>pp2 : string

strOrNum = typeof this.pp3 === "string" && this.pp3; // string | number
>strOrNum = typeof this.pp3 === "string" && this.pp3 : string | number
>strOrNum = typeof this.pp3 === "string" && this.pp3 : string
>strOrNum : string | number
>typeof this.pp3 === "string" && this.pp3 : string | number
>typeof this.pp3 === "string" && this.pp3 : string
>typeof this.pp3 === "string" : boolean
>typeof this.pp3 : string
>this.pp3 : string | number
>this : this
>pp3 : string | number
>"string" : string
>this.pp3 : string | number
>this.pp3 : string
>this : this
>pp3 : string | number
>pp3 : string
}
}
var c1: C1;
Expand All @@ -90,18 +90,18 @@ strOrNum = typeof c1.pp2 === "string" && c1.pp2; // string | number
>pp2 : string

strOrNum = typeof c1.pp3 === "string" && c1.pp3; // string | number
>strOrNum = typeof c1.pp3 === "string" && c1.pp3 : string | number
>strOrNum = typeof c1.pp3 === "string" && c1.pp3 : string
>strOrNum : string | number
>typeof c1.pp3 === "string" && c1.pp3 : string | number
>typeof c1.pp3 === "string" && c1.pp3 : string
>typeof c1.pp3 === "string" : boolean
>typeof c1.pp3 : string
>c1.pp3 : string | number
>c1 : C1
>pp3 : string | number
>"string" : string
>c1.pp3 : string | number
>c1.pp3 : string
>c1 : C1
>pp3 : string | number
>pp3 : string

var obj1: {
>obj1 : { x: string | number; }
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/typeGuardsObjectMethods.types
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,16 @@ strOrNum = typeof obj1.method(strOrNum) === "string" && obj1.method(strOrNum);

// accessing getter property
strOrNum = typeof obj1.prop === "string" && obj1.prop;
>strOrNum = typeof obj1.prop === "string" && obj1.prop : string | number
>strOrNum = typeof obj1.prop === "string" && obj1.prop : string
>strOrNum : string | number
>typeof obj1.prop === "string" && obj1.prop : string | number
>typeof obj1.prop === "string" && obj1.prop : string
>typeof obj1.prop === "string" : boolean
>typeof obj1.prop : string
>obj1.prop : string | number
>obj1 : { method(param: string | number): string | number; prop: string | number; }
>prop : string | number
>"string" : string
>obj1.prop : string | number
>obj1.prop : string
>obj1 : { method(param: string | number): string | number; prop: string | number; }
>prop : string | number
>prop : string