From c3186a452c29b02ec7062fdc9dd0cff4f33a2aba Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 3 May 2016 11:09:21 -0700 Subject: [PATCH 1/2] Include accessors in control flow type analysis --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bf0ba6beb25..df3528a17ac 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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); From c44fe766dc3d6d614d2bcf5ae6f76857e8d3a1eb Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 3 May 2016 11:09:37 -0700 Subject: [PATCH 2/2] Accepting new baselines --- .../reference/typeGuardsInProperties.types | 16 ++++++++-------- .../reference/typeGuardsObjectMethods.types | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/baselines/reference/typeGuardsInProperties.types b/tests/baselines/reference/typeGuardsInProperties.types index ef4cfbb5b05..4ddf8af7a67 100644 --- a/tests/baselines/reference/typeGuardsInProperties.types +++ b/tests/baselines/reference/typeGuardsInProperties.types @@ -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; @@ -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; } diff --git a/tests/baselines/reference/typeGuardsObjectMethods.types b/tests/baselines/reference/typeGuardsObjectMethods.types index 4ca691bc020..f409bf5caf9 100644 --- a/tests/baselines/reference/typeGuardsObjectMethods.types +++ b/tests/baselines/reference/typeGuardsObjectMethods.types @@ -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