mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-27 04:48:33 -05:00
Change isTypePresencePossible, accept baseline
This commit is contained in:
@@ -12722,30 +12722,18 @@ namespace ts {
|
||||
return type;
|
||||
}
|
||||
|
||||
function isTypePresencePossible(type: Type, propName: string, shouldHaveProperty: boolean) {
|
||||
function isTypePresencePossible(type: Type, propName: __String, assumeTrue: boolean) {
|
||||
const prop = getPropertyOfType(type, propName);
|
||||
if (!prop) {
|
||||
// if there is NO property:
|
||||
// - but we assume type SHOULD have it then presence of object of following type IS NOT possible
|
||||
// - and we assume type SHOULD NOT have it then presence of object of following type IS possible
|
||||
return !shouldHaveProperty;
|
||||
} else if (prop.flags & SymbolFlags.Optional) {
|
||||
// if there is an optional property:
|
||||
// - and we assume type SHOULD have it then presence of object of following type IS possible
|
||||
// - but assume type SHOULD NOT have it then presence of object of following type IS still possible
|
||||
return true;
|
||||
} else /* if (prop.flags & SymbolFlags.Required) */ {
|
||||
// if there is a required property:
|
||||
// - and we assume type SHOULD have it then presence of object of following type IS possible
|
||||
// - but we assume type SHOULD NOT have it then presence of object of following type IS NOT possible
|
||||
return shouldHaveProperty;
|
||||
if (prop) {
|
||||
return (prop.flags & SymbolFlags.Optional) ? true : assumeTrue;
|
||||
}
|
||||
return !assumeTrue;
|
||||
}
|
||||
|
||||
function narrowByInKeyword(type: Type, literal: LiteralExpression, assumeTrue: boolean) {
|
||||
if ((type.flags & (TypeFlags.Union | TypeFlags.Object)) || (type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType)) {
|
||||
const propName = literal.text;
|
||||
return filterType(type, t => isTypePresencePossible(t, propName, /* shouldHaveProperty */ assumeTrue));
|
||||
const propName = escapeLeadingUnderscores(literal.text);
|
||||
return filterType(type, t => isTypePresencePossible(t, propName, /* assumeTrue */ assumeTrue));
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ tests/cases/conformance/fixSignatureCaching.ts(284,10): error TS2339: Property '
|
||||
tests/cases/conformance/fixSignatureCaching.ts(293,10): error TS2339: Property 'FALLBACK_PHONE' does not exist on type '{}'.
|
||||
tests/cases/conformance/fixSignatureCaching.ts(294,10): error TS2339: Property 'FALLBACK_TABLET' does not exist on type '{}'.
|
||||
tests/cases/conformance/fixSignatureCaching.ts(295,10): error TS2339: Property 'FALLBACK_MOBILE' does not exist on type '{}'.
|
||||
tests/cases/conformance/fixSignatureCaching.ts(301,17): error TS2339: Property 'isArray' does not exist on type 'never'.
|
||||
tests/cases/conformance/fixSignatureCaching.ts(330,74): error TS2339: Property 'mobileDetectRules' does not exist on type '{}'.
|
||||
tests/cases/conformance/fixSignatureCaching.ts(369,10): error TS2339: Property 'findMatch' does not exist on type '{}'.
|
||||
tests/cases/conformance/fixSignatureCaching.ts(387,10): error TS2339: Property 'findMatches' does not exist on type '{}'.
|
||||
@@ -71,7 +72,7 @@ tests/cases/conformance/fixSignatureCaching.ts(982,23): error TS2304: Cannot fin
|
||||
tests/cases/conformance/fixSignatureCaching.ts(983,37): error TS2304: Cannot find name 'window'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/fixSignatureCaching.ts (71 errors) ====
|
||||
==== tests/cases/conformance/fixSignatureCaching.ts (72 errors) ====
|
||||
// Repro from #10697
|
||||
|
||||
(function (define, undefined) {
|
||||
@@ -383,6 +384,8 @@ tests/cases/conformance/fixSignatureCaching.ts(983,37): error TS2304: Cannot fin
|
||||
isArray = 'isArray' in Array
|
||||
? function (value) { return Object.prototype.toString.call(value) === '[object Array]'; }
|
||||
: Array.isArray;
|
||||
~~~~~~~
|
||||
!!! error TS2339: Property 'isArray' does not exist on type 'never'.
|
||||
|
||||
function equalIC(a, b) {
|
||||
return a != null && b != null && a.toLowerCase() === b.toLowerCase();
|
||||
|
||||
@@ -358,9 +358,7 @@ define(function () {
|
||||
>value : Symbol(value, Decl(fixSignatureCaching.ts, 299, 20))
|
||||
|
||||
: Array.isArray;
|
||||
>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.d.ts, --, --))
|
||||
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.d.ts, --, --))
|
||||
|
||||
function equalIC(a, b) {
|
||||
>equalIC : Symbol(equalIC, Decl(fixSignatureCaching.ts, 300, 24))
|
||||
|
||||
@@ -893,9 +893,9 @@ define(function () {
|
||||
>'[object Array]' : "[object Array]"
|
||||
|
||||
isArray = 'isArray' in Array
|
||||
>isArray = 'isArray' in Array ? function (value) { return Object.prototype.toString.call(value) === '[object Array]'; } : Array.isArray : (value: any) => boolean
|
||||
>isArray = 'isArray' in Array ? function (value) { return Object.prototype.toString.call(value) === '[object Array]'; } : Array.isArray : any
|
||||
>isArray : any
|
||||
>'isArray' in Array ? function (value) { return Object.prototype.toString.call(value) === '[object Array]'; } : Array.isArray : (value: any) => boolean
|
||||
>'isArray' in Array ? function (value) { return Object.prototype.toString.call(value) === '[object Array]'; } : Array.isArray : any
|
||||
>'isArray' in Array : boolean
|
||||
>'isArray' : "isArray"
|
||||
>Array : ArrayConstructor
|
||||
@@ -916,9 +916,9 @@ define(function () {
|
||||
>'[object Array]' : "[object Array]"
|
||||
|
||||
: Array.isArray;
|
||||
>Array.isArray : (arg: any) => arg is any[]
|
||||
>Array : ArrayConstructor
|
||||
>isArray : (arg: any) => arg is any[]
|
||||
>Array.isArray : any
|
||||
>Array : never
|
||||
>isArray : any
|
||||
|
||||
function equalIC(a, b) {
|
||||
>equalIC : (a: any, b: any) => boolean
|
||||
|
||||
@@ -98,12 +98,12 @@ class UnreachableCodeDetection {
|
||||
}
|
||||
|
||||
//// [inKeywordTypeguard.js]
|
||||
var A = (function () {
|
||||
var A = /** @class */ (function () {
|
||||
function A() {
|
||||
}
|
||||
return A;
|
||||
}());
|
||||
var B = (function () {
|
||||
var B = /** @class */ (function () {
|
||||
function B() {
|
||||
}
|
||||
return B;
|
||||
@@ -124,12 +124,12 @@ function positiveClassesTest(x) {
|
||||
x.a = "1";
|
||||
}
|
||||
}
|
||||
var AWithOptionalProp = (function () {
|
||||
var AWithOptionalProp = /** @class */ (function () {
|
||||
function AWithOptionalProp() {
|
||||
}
|
||||
return AWithOptionalProp;
|
||||
}());
|
||||
var BWithOptionalProp = (function () {
|
||||
var BWithOptionalProp = /** @class */ (function () {
|
||||
function BWithOptionalProp() {
|
||||
}
|
||||
return BWithOptionalProp;
|
||||
@@ -142,13 +142,13 @@ function positiveTestClassesWithOptionalProperties(x) {
|
||||
x.b = "1";
|
||||
}
|
||||
}
|
||||
var AWithMethod = (function () {
|
||||
var AWithMethod = /** @class */ (function () {
|
||||
function AWithMethod() {
|
||||
}
|
||||
AWithMethod.prototype.a = function () { return ""; };
|
||||
return AWithMethod;
|
||||
}());
|
||||
var BWithMethod = (function () {
|
||||
var BWithMethod = /** @class */ (function () {
|
||||
function BWithMethod() {
|
||||
}
|
||||
BWithMethod.prototype.b = function () { return ""; };
|
||||
@@ -172,12 +172,12 @@ function negativeTestClassesWithMemberMissingInBothClasses(x) {
|
||||
x.b();
|
||||
}
|
||||
}
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
}());
|
||||
var D = (function () {
|
||||
var D = /** @class */ (function () {
|
||||
function D() {
|
||||
}
|
||||
return D;
|
||||
@@ -190,7 +190,7 @@ function negativeMultipleClassesTest(x) {
|
||||
x.a = "1";
|
||||
}
|
||||
}
|
||||
var ClassWithUnionProp = (function () {
|
||||
var ClassWithUnionProp = /** @class */ (function () {
|
||||
function ClassWithUnionProp() {
|
||||
}
|
||||
return ClassWithUnionProp;
|
||||
@@ -203,7 +203,7 @@ function negativePropTest(x) {
|
||||
var z = x.prop.a;
|
||||
}
|
||||
}
|
||||
var NegativeClassTest = (function () {
|
||||
var NegativeClassTest = /** @class */ (function () {
|
||||
function NegativeClassTest() {
|
||||
}
|
||||
NegativeClassTest.prototype.inThis = function () {
|
||||
@@ -216,7 +216,7 @@ var NegativeClassTest = (function () {
|
||||
};
|
||||
return NegativeClassTest;
|
||||
}());
|
||||
var UnreachableCodeDetection = (function () {
|
||||
var UnreachableCodeDetection = /** @class */ (function () {
|
||||
function UnreachableCodeDetection() {
|
||||
}
|
||||
UnreachableCodeDetection.prototype.inThis = function () {
|
||||
|
||||
241
tests/baselines/reference/inKeywordTypeguard.symbols
Normal file
241
tests/baselines/reference/inKeywordTypeguard.symbols
Normal file
@@ -0,0 +1,241 @@
|
||||
=== tests/cases/compiler/inKeywordTypeguard.ts ===
|
||||
class A { a: string; }
|
||||
>A : Symbol(A, Decl(inKeywordTypeguard.ts, 0, 0))
|
||||
>a : Symbol(A.a, Decl(inKeywordTypeguard.ts, 0, 9))
|
||||
|
||||
class B { b: string; }
|
||||
>B : Symbol(B, Decl(inKeywordTypeguard.ts, 0, 22))
|
||||
>b : Symbol(B.b, Decl(inKeywordTypeguard.ts, 1, 9))
|
||||
|
||||
function negativeClassesTest(x: A | B) {
|
||||
>negativeClassesTest : Symbol(negativeClassesTest, Decl(inKeywordTypeguard.ts, 1, 22))
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 3, 29))
|
||||
>A : Symbol(A, Decl(inKeywordTypeguard.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(inKeywordTypeguard.ts, 0, 22))
|
||||
|
||||
if ("a" in x) {
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 3, 29))
|
||||
|
||||
x.b = "1";
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 3, 29))
|
||||
|
||||
} else {
|
||||
x.a = "1";
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 3, 29))
|
||||
}
|
||||
}
|
||||
|
||||
function positiveClassesTest(x: A | B) {
|
||||
>positiveClassesTest : Symbol(positiveClassesTest, Decl(inKeywordTypeguard.ts, 9, 1))
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 11, 29))
|
||||
>A : Symbol(A, Decl(inKeywordTypeguard.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(inKeywordTypeguard.ts, 0, 22))
|
||||
|
||||
if ("a" in x) {
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 11, 29))
|
||||
|
||||
x.b = "1";
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 11, 29))
|
||||
|
||||
} else {
|
||||
x.a = "1";
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 11, 29))
|
||||
}
|
||||
}
|
||||
|
||||
class AWithOptionalProp { a?: string; }
|
||||
>AWithOptionalProp : Symbol(AWithOptionalProp, Decl(inKeywordTypeguard.ts, 17, 1))
|
||||
>a : Symbol(AWithOptionalProp.a, Decl(inKeywordTypeguard.ts, 19, 25))
|
||||
|
||||
class BWithOptionalProp { b?: string; }
|
||||
>BWithOptionalProp : Symbol(BWithOptionalProp, Decl(inKeywordTypeguard.ts, 19, 39))
|
||||
>b : Symbol(BWithOptionalProp.b, Decl(inKeywordTypeguard.ts, 20, 25))
|
||||
|
||||
function positiveTestClassesWithOptionalProperties(x: AWithOptionalProp | BWithOptionalProp) {
|
||||
>positiveTestClassesWithOptionalProperties : Symbol(positiveTestClassesWithOptionalProperties, Decl(inKeywordTypeguard.ts, 20, 39))
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 22, 51))
|
||||
>AWithOptionalProp : Symbol(AWithOptionalProp, Decl(inKeywordTypeguard.ts, 17, 1))
|
||||
>BWithOptionalProp : Symbol(BWithOptionalProp, Decl(inKeywordTypeguard.ts, 19, 39))
|
||||
|
||||
if ("a" in x) {
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 22, 51))
|
||||
|
||||
x.a = "1";
|
||||
>x.a : Symbol(AWithOptionalProp.a, Decl(inKeywordTypeguard.ts, 19, 25))
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 22, 51))
|
||||
>a : Symbol(AWithOptionalProp.a, Decl(inKeywordTypeguard.ts, 19, 25))
|
||||
|
||||
} else {
|
||||
x.b = "1";
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 22, 51))
|
||||
}
|
||||
}
|
||||
|
||||
class AWithMethod {
|
||||
>AWithMethod : Symbol(AWithMethod, Decl(inKeywordTypeguard.ts, 28, 1))
|
||||
|
||||
a(): string { return ""; }
|
||||
>a : Symbol(AWithMethod.a, Decl(inKeywordTypeguard.ts, 30, 19))
|
||||
}
|
||||
|
||||
class BWithMethod {
|
||||
>BWithMethod : Symbol(BWithMethod, Decl(inKeywordTypeguard.ts, 32, 1))
|
||||
|
||||
b(): string { return ""; }
|
||||
>b : Symbol(BWithMethod.b, Decl(inKeywordTypeguard.ts, 34, 19))
|
||||
}
|
||||
|
||||
function negativeTestClassesWithMembers(x: AWithMethod | BWithMethod) {
|
||||
>negativeTestClassesWithMembers : Symbol(negativeTestClassesWithMembers, Decl(inKeywordTypeguard.ts, 36, 1))
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 38, 40))
|
||||
>AWithMethod : Symbol(AWithMethod, Decl(inKeywordTypeguard.ts, 28, 1))
|
||||
>BWithMethod : Symbol(BWithMethod, Decl(inKeywordTypeguard.ts, 32, 1))
|
||||
|
||||
if ("a" in x) {
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 38, 40))
|
||||
|
||||
x.a();
|
||||
>x.a : Symbol(AWithMethod.a, Decl(inKeywordTypeguard.ts, 30, 19))
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 38, 40))
|
||||
>a : Symbol(AWithMethod.a, Decl(inKeywordTypeguard.ts, 30, 19))
|
||||
|
||||
x.b();
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 38, 40))
|
||||
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
function negativeTestClassesWithMemberMissingInBothClasses(x: AWithMethod | BWithMethod) {
|
||||
>negativeTestClassesWithMemberMissingInBothClasses : Symbol(negativeTestClassesWithMemberMissingInBothClasses, Decl(inKeywordTypeguard.ts, 44, 1))
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 46, 59))
|
||||
>AWithMethod : Symbol(AWithMethod, Decl(inKeywordTypeguard.ts, 28, 1))
|
||||
>BWithMethod : Symbol(BWithMethod, Decl(inKeywordTypeguard.ts, 32, 1))
|
||||
|
||||
if ("c" in x) {
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 46, 59))
|
||||
|
||||
x.a();
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 46, 59))
|
||||
|
||||
x.b();
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 46, 59))
|
||||
|
||||
} else {
|
||||
x.a();
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 46, 59))
|
||||
|
||||
x.b();
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 46, 59))
|
||||
}
|
||||
}
|
||||
|
||||
class C { a: string; }
|
||||
>C : Symbol(C, Decl(inKeywordTypeguard.ts, 54, 1))
|
||||
>a : Symbol(C.a, Decl(inKeywordTypeguard.ts, 56, 9))
|
||||
|
||||
class D { a: string; }
|
||||
>D : Symbol(D, Decl(inKeywordTypeguard.ts, 56, 22))
|
||||
>a : Symbol(D.a, Decl(inKeywordTypeguard.ts, 57, 9))
|
||||
|
||||
function negativeMultipleClassesTest(x: A | B | C | D) {
|
||||
>negativeMultipleClassesTest : Symbol(negativeMultipleClassesTest, Decl(inKeywordTypeguard.ts, 57, 22))
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 59, 37))
|
||||
>A : Symbol(A, Decl(inKeywordTypeguard.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(inKeywordTypeguard.ts, 0, 22))
|
||||
>C : Symbol(C, Decl(inKeywordTypeguard.ts, 54, 1))
|
||||
>D : Symbol(D, Decl(inKeywordTypeguard.ts, 56, 22))
|
||||
|
||||
if ("a" in x) {
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 59, 37))
|
||||
|
||||
x.b = "1";
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 59, 37))
|
||||
|
||||
} else {
|
||||
x.a = "1";
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 59, 37))
|
||||
}
|
||||
}
|
||||
|
||||
class ClassWithUnionProp { prop: A | B }
|
||||
>ClassWithUnionProp : Symbol(ClassWithUnionProp, Decl(inKeywordTypeguard.ts, 65, 1))
|
||||
>prop : Symbol(ClassWithUnionProp.prop, Decl(inKeywordTypeguard.ts, 67, 26))
|
||||
>A : Symbol(A, Decl(inKeywordTypeguard.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(inKeywordTypeguard.ts, 0, 22))
|
||||
|
||||
function negativePropTest(x: ClassWithUnionProp) {
|
||||
>negativePropTest : Symbol(negativePropTest, Decl(inKeywordTypeguard.ts, 67, 40))
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 69, 26))
|
||||
>ClassWithUnionProp : Symbol(ClassWithUnionProp, Decl(inKeywordTypeguard.ts, 65, 1))
|
||||
|
||||
if ("a" in x.prop) {
|
||||
>x.prop : Symbol(ClassWithUnionProp.prop, Decl(inKeywordTypeguard.ts, 67, 26))
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 69, 26))
|
||||
>prop : Symbol(ClassWithUnionProp.prop, Decl(inKeywordTypeguard.ts, 67, 26))
|
||||
|
||||
let y: string = x.prop.b;
|
||||
>y : Symbol(y, Decl(inKeywordTypeguard.ts, 71, 11))
|
||||
>x.prop : Symbol(ClassWithUnionProp.prop, Decl(inKeywordTypeguard.ts, 67, 26))
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 69, 26))
|
||||
>prop : Symbol(ClassWithUnionProp.prop, Decl(inKeywordTypeguard.ts, 67, 26))
|
||||
|
||||
} else {
|
||||
let z: string = x.prop.a;
|
||||
>z : Symbol(z, Decl(inKeywordTypeguard.ts, 73, 11))
|
||||
>x.prop : Symbol(ClassWithUnionProp.prop, Decl(inKeywordTypeguard.ts, 67, 26))
|
||||
>x : Symbol(x, Decl(inKeywordTypeguard.ts, 69, 26))
|
||||
>prop : Symbol(ClassWithUnionProp.prop, Decl(inKeywordTypeguard.ts, 67, 26))
|
||||
}
|
||||
}
|
||||
|
||||
class NegativeClassTest {
|
||||
>NegativeClassTest : Symbol(NegativeClassTest, Decl(inKeywordTypeguard.ts, 75, 1))
|
||||
|
||||
protected prop: A | B;
|
||||
>prop : Symbol(NegativeClassTest.prop, Decl(inKeywordTypeguard.ts, 77, 25))
|
||||
>A : Symbol(A, Decl(inKeywordTypeguard.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(inKeywordTypeguard.ts, 0, 22))
|
||||
|
||||
inThis() {
|
||||
>inThis : Symbol(NegativeClassTest.inThis, Decl(inKeywordTypeguard.ts, 78, 26))
|
||||
|
||||
if ("a" in this.prop) {
|
||||
>this.prop : Symbol(NegativeClassTest.prop, Decl(inKeywordTypeguard.ts, 77, 25))
|
||||
>this : Symbol(NegativeClassTest, Decl(inKeywordTypeguard.ts, 75, 1))
|
||||
>prop : Symbol(NegativeClassTest.prop, Decl(inKeywordTypeguard.ts, 77, 25))
|
||||
|
||||
let z: number = this.prop.b;
|
||||
>z : Symbol(z, Decl(inKeywordTypeguard.ts, 81, 15))
|
||||
>this.prop : Symbol(NegativeClassTest.prop, Decl(inKeywordTypeguard.ts, 77, 25))
|
||||
>this : Symbol(NegativeClassTest, Decl(inKeywordTypeguard.ts, 75, 1))
|
||||
>prop : Symbol(NegativeClassTest.prop, Decl(inKeywordTypeguard.ts, 77, 25))
|
||||
|
||||
} else {
|
||||
let y: string = this.prop.a;
|
||||
>y : Symbol(y, Decl(inKeywordTypeguard.ts, 83, 15))
|
||||
>this.prop : Symbol(NegativeClassTest.prop, Decl(inKeywordTypeguard.ts, 77, 25))
|
||||
>this : Symbol(NegativeClassTest, Decl(inKeywordTypeguard.ts, 75, 1))
|
||||
>prop : Symbol(NegativeClassTest.prop, Decl(inKeywordTypeguard.ts, 77, 25))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UnreachableCodeDetection {
|
||||
>UnreachableCodeDetection : Symbol(UnreachableCodeDetection, Decl(inKeywordTypeguard.ts, 86, 1))
|
||||
|
||||
a: string;
|
||||
>a : Symbol(UnreachableCodeDetection.a, Decl(inKeywordTypeguard.ts, 88, 32))
|
||||
|
||||
inThis() {
|
||||
>inThis : Symbol(UnreachableCodeDetection.inThis, Decl(inKeywordTypeguard.ts, 89, 14))
|
||||
|
||||
if ("a" in this) {
|
||||
>this : Symbol(UnreachableCodeDetection, Decl(inKeywordTypeguard.ts, 86, 1))
|
||||
|
||||
} else {
|
||||
let y = this.a;
|
||||
>y : Symbol(y, Decl(inKeywordTypeguard.ts, 93, 15))
|
||||
}
|
||||
}
|
||||
}
|
||||
318
tests/baselines/reference/inKeywordTypeguard.types
Normal file
318
tests/baselines/reference/inKeywordTypeguard.types
Normal file
@@ -0,0 +1,318 @@
|
||||
=== tests/cases/compiler/inKeywordTypeguard.ts ===
|
||||
class A { a: string; }
|
||||
>A : A
|
||||
>a : string
|
||||
|
||||
class B { b: string; }
|
||||
>B : B
|
||||
>b : string
|
||||
|
||||
function negativeClassesTest(x: A | B) {
|
||||
>negativeClassesTest : (x: A | B) => void
|
||||
>x : A | B
|
||||
>A : A
|
||||
>B : B
|
||||
|
||||
if ("a" in x) {
|
||||
>"a" in x : boolean
|
||||
>"a" : "a"
|
||||
>x : A | B
|
||||
|
||||
x.b = "1";
|
||||
>x.b = "1" : "1"
|
||||
>x.b : any
|
||||
>x : A
|
||||
>b : any
|
||||
>"1" : "1"
|
||||
|
||||
} else {
|
||||
x.a = "1";
|
||||
>x.a = "1" : "1"
|
||||
>x.a : any
|
||||
>x : B
|
||||
>a : any
|
||||
>"1" : "1"
|
||||
}
|
||||
}
|
||||
|
||||
function positiveClassesTest(x: A | B) {
|
||||
>positiveClassesTest : (x: A | B) => void
|
||||
>x : A | B
|
||||
>A : A
|
||||
>B : B
|
||||
|
||||
if ("a" in x) {
|
||||
>"a" in x : boolean
|
||||
>"a" : "a"
|
||||
>x : A | B
|
||||
|
||||
x.b = "1";
|
||||
>x.b = "1" : "1"
|
||||
>x.b : any
|
||||
>x : A
|
||||
>b : any
|
||||
>"1" : "1"
|
||||
|
||||
} else {
|
||||
x.a = "1";
|
||||
>x.a = "1" : "1"
|
||||
>x.a : any
|
||||
>x : B
|
||||
>a : any
|
||||
>"1" : "1"
|
||||
}
|
||||
}
|
||||
|
||||
class AWithOptionalProp { a?: string; }
|
||||
>AWithOptionalProp : AWithOptionalProp
|
||||
>a : string
|
||||
|
||||
class BWithOptionalProp { b?: string; }
|
||||
>BWithOptionalProp : BWithOptionalProp
|
||||
>b : string
|
||||
|
||||
function positiveTestClassesWithOptionalProperties(x: AWithOptionalProp | BWithOptionalProp) {
|
||||
>positiveTestClassesWithOptionalProperties : (x: AWithOptionalProp | BWithOptionalProp) => void
|
||||
>x : AWithOptionalProp | BWithOptionalProp
|
||||
>AWithOptionalProp : AWithOptionalProp
|
||||
>BWithOptionalProp : BWithOptionalProp
|
||||
|
||||
if ("a" in x) {
|
||||
>"a" in x : boolean
|
||||
>"a" : "a"
|
||||
>x : AWithOptionalProp | BWithOptionalProp
|
||||
|
||||
x.a = "1";
|
||||
>x.a = "1" : "1"
|
||||
>x.a : string
|
||||
>x : AWithOptionalProp
|
||||
>a : string
|
||||
>"1" : "1"
|
||||
|
||||
} else {
|
||||
x.b = "1";
|
||||
>x.b = "1" : "1"
|
||||
>x.b : any
|
||||
>x : AWithOptionalProp | BWithOptionalProp
|
||||
>b : any
|
||||
>"1" : "1"
|
||||
}
|
||||
}
|
||||
|
||||
class AWithMethod {
|
||||
>AWithMethod : AWithMethod
|
||||
|
||||
a(): string { return ""; }
|
||||
>a : () => string
|
||||
>"" : ""
|
||||
}
|
||||
|
||||
class BWithMethod {
|
||||
>BWithMethod : BWithMethod
|
||||
|
||||
b(): string { return ""; }
|
||||
>b : () => string
|
||||
>"" : ""
|
||||
}
|
||||
|
||||
function negativeTestClassesWithMembers(x: AWithMethod | BWithMethod) {
|
||||
>negativeTestClassesWithMembers : (x: AWithMethod | BWithMethod) => void
|
||||
>x : AWithMethod | BWithMethod
|
||||
>AWithMethod : AWithMethod
|
||||
>BWithMethod : BWithMethod
|
||||
|
||||
if ("a" in x) {
|
||||
>"a" in x : boolean
|
||||
>"a" : "a"
|
||||
>x : AWithMethod | BWithMethod
|
||||
|
||||
x.a();
|
||||
>x.a() : string
|
||||
>x.a : () => string
|
||||
>x : AWithMethod
|
||||
>a : () => string
|
||||
|
||||
x.b();
|
||||
>x.b() : any
|
||||
>x.b : any
|
||||
>x : AWithMethod
|
||||
>b : any
|
||||
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
function negativeTestClassesWithMemberMissingInBothClasses(x: AWithMethod | BWithMethod) {
|
||||
>negativeTestClassesWithMemberMissingInBothClasses : (x: AWithMethod | BWithMethod) => void
|
||||
>x : AWithMethod | BWithMethod
|
||||
>AWithMethod : AWithMethod
|
||||
>BWithMethod : BWithMethod
|
||||
|
||||
if ("c" in x) {
|
||||
>"c" in x : boolean
|
||||
>"c" : "c"
|
||||
>x : AWithMethod | BWithMethod
|
||||
|
||||
x.a();
|
||||
>x.a() : any
|
||||
>x.a : any
|
||||
>x : never
|
||||
>a : any
|
||||
|
||||
x.b();
|
||||
>x.b() : any
|
||||
>x.b : any
|
||||
>x : never
|
||||
>b : any
|
||||
|
||||
} else {
|
||||
x.a();
|
||||
>x.a() : any
|
||||
>x.a : any
|
||||
>x : AWithMethod | BWithMethod
|
||||
>a : any
|
||||
|
||||
x.b();
|
||||
>x.b() : any
|
||||
>x.b : any
|
||||
>x : AWithMethod | BWithMethod
|
||||
>b : any
|
||||
}
|
||||
}
|
||||
|
||||
class C { a: string; }
|
||||
>C : C
|
||||
>a : string
|
||||
|
||||
class D { a: string; }
|
||||
>D : D
|
||||
>a : string
|
||||
|
||||
function negativeMultipleClassesTest(x: A | B | C | D) {
|
||||
>negativeMultipleClassesTest : (x: A | B | C | D) => void
|
||||
>x : A | B | C | D
|
||||
>A : A
|
||||
>B : B
|
||||
>C : C
|
||||
>D : D
|
||||
|
||||
if ("a" in x) {
|
||||
>"a" in x : boolean
|
||||
>"a" : "a"
|
||||
>x : A | B | C | D
|
||||
|
||||
x.b = "1";
|
||||
>x.b = "1" : "1"
|
||||
>x.b : any
|
||||
>x : A | C | D
|
||||
>b : any
|
||||
>"1" : "1"
|
||||
|
||||
} else {
|
||||
x.a = "1";
|
||||
>x.a = "1" : "1"
|
||||
>x.a : any
|
||||
>x : B
|
||||
>a : any
|
||||
>"1" : "1"
|
||||
}
|
||||
}
|
||||
|
||||
class ClassWithUnionProp { prop: A | B }
|
||||
>ClassWithUnionProp : ClassWithUnionProp
|
||||
>prop : A | B
|
||||
>A : A
|
||||
>B : B
|
||||
|
||||
function negativePropTest(x: ClassWithUnionProp) {
|
||||
>negativePropTest : (x: ClassWithUnionProp) => void
|
||||
>x : ClassWithUnionProp
|
||||
>ClassWithUnionProp : ClassWithUnionProp
|
||||
|
||||
if ("a" in x.prop) {
|
||||
>"a" in x.prop : boolean
|
||||
>"a" : "a"
|
||||
>x.prop : A | B
|
||||
>x : ClassWithUnionProp
|
||||
>prop : A | B
|
||||
|
||||
let y: string = x.prop.b;
|
||||
>y : string
|
||||
>x.prop.b : any
|
||||
>x.prop : A
|
||||
>x : ClassWithUnionProp
|
||||
>prop : A
|
||||
>b : any
|
||||
|
||||
} else {
|
||||
let z: string = x.prop.a;
|
||||
>z : string
|
||||
>x.prop.a : any
|
||||
>x.prop : B
|
||||
>x : ClassWithUnionProp
|
||||
>prop : B
|
||||
>a : any
|
||||
}
|
||||
}
|
||||
|
||||
class NegativeClassTest {
|
||||
>NegativeClassTest : NegativeClassTest
|
||||
|
||||
protected prop: A | B;
|
||||
>prop : A | B
|
||||
>A : A
|
||||
>B : B
|
||||
|
||||
inThis() {
|
||||
>inThis : () => void
|
||||
|
||||
if ("a" in this.prop) {
|
||||
>"a" in this.prop : boolean
|
||||
>"a" : "a"
|
||||
>this.prop : A | B
|
||||
>this : this
|
||||
>prop : A | B
|
||||
|
||||
let z: number = this.prop.b;
|
||||
>z : number
|
||||
>this.prop.b : any
|
||||
>this.prop : A
|
||||
>this : this
|
||||
>prop : A
|
||||
>b : any
|
||||
|
||||
} else {
|
||||
let y: string = this.prop.a;
|
||||
>y : string
|
||||
>this.prop.a : any
|
||||
>this.prop : B
|
||||
>this : this
|
||||
>prop : B
|
||||
>a : any
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UnreachableCodeDetection {
|
||||
>UnreachableCodeDetection : UnreachableCodeDetection
|
||||
|
||||
a: string;
|
||||
>a : string
|
||||
|
||||
inThis() {
|
||||
>inThis : () => void
|
||||
|
||||
if ("a" in this) {
|
||||
>"a" in this : boolean
|
||||
>"a" : "a"
|
||||
>this : this
|
||||
|
||||
} else {
|
||||
let y = this.a;
|
||||
>y : any
|
||||
>this.a : any
|
||||
>this : never
|
||||
>a : any
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,22 +92,22 @@ class SelfAssert {
|
||||
}
|
||||
|
||||
//// [typeGuardOfFromPropNameInUnionType.js]
|
||||
var A = (function () {
|
||||
var A = /** @class */ (function () {
|
||||
function A() {
|
||||
}
|
||||
return A;
|
||||
}());
|
||||
var B = (function () {
|
||||
var B = /** @class */ (function () {
|
||||
function B() {
|
||||
}
|
||||
return B;
|
||||
}());
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
}());
|
||||
var D = (function () {
|
||||
var D = /** @class */ (function () {
|
||||
function D() {
|
||||
}
|
||||
return D;
|
||||
@@ -136,12 +136,12 @@ function anonymousClasses(x) {
|
||||
var z = x.b;
|
||||
}
|
||||
}
|
||||
var AWithOptionalProp = (function () {
|
||||
var AWithOptionalProp = /** @class */ (function () {
|
||||
function AWithOptionalProp() {
|
||||
}
|
||||
return AWithOptionalProp;
|
||||
}());
|
||||
var BWithOptionalProp = (function () {
|
||||
var BWithOptionalProp = /** @class */ (function () {
|
||||
function BWithOptionalProp() {
|
||||
}
|
||||
return BWithOptionalProp;
|
||||
@@ -164,7 +164,7 @@ function inParenthesizedExpression(x) {
|
||||
var z = x.b;
|
||||
}
|
||||
}
|
||||
var ClassWithUnionProp = (function () {
|
||||
var ClassWithUnionProp = /** @class */ (function () {
|
||||
function ClassWithUnionProp() {
|
||||
}
|
||||
return ClassWithUnionProp;
|
||||
@@ -177,7 +177,7 @@ function inProperty(x) {
|
||||
var z = x.prop.b;
|
||||
}
|
||||
}
|
||||
var NestedClassWithProp = (function () {
|
||||
var NestedClassWithProp = /** @class */ (function () {
|
||||
function NestedClassWithProp() {
|
||||
}
|
||||
return NestedClassWithProp;
|
||||
@@ -190,7 +190,7 @@ function innestedProperty(x) {
|
||||
var z = x.outer.prop.b;
|
||||
}
|
||||
}
|
||||
var InMemberOfClass = (function () {
|
||||
var InMemberOfClass = /** @class */ (function () {
|
||||
function InMemberOfClass() {
|
||||
}
|
||||
InMemberOfClass.prototype.inThis = function () {
|
||||
@@ -204,7 +204,7 @@ var InMemberOfClass = (function () {
|
||||
return InMemberOfClass;
|
||||
}());
|
||||
// added for completeness
|
||||
var SelfAssert = (function () {
|
||||
var SelfAssert = /** @class */ (function () {
|
||||
function SelfAssert() {
|
||||
}
|
||||
SelfAssert.prototype.inThis = function () {
|
||||
|
||||
Reference in New Issue
Block a user