diff --git a/tests/baselines/reference/typeGuardOfFromPropNameInUnionType.js b/tests/baselines/reference/typeGuardOfFromPropNameInUnionType.js index a2579328646..47b57a51927 100644 --- a/tests/baselines/reference/typeGuardOfFromPropNameInUnionType.js +++ b/tests/baselines/reference/typeGuardOfFromPropNameInUnionType.js @@ -89,7 +89,22 @@ class SelfAssert { } else { } } -} +} + +interface Indexed { + [s: string]: any; +} + +function f(i: Indexed) { + if ("a" in i) { + return i.a; + } + else if ("b" in i) { + return i.b; + } + return "c" in i && i.c; +} + //// [typeGuardOfFromPropNameInUnionType.js] var A = /** @class */ (function () { @@ -216,3 +231,12 @@ var SelfAssert = /** @class */ (function () { }; return SelfAssert; }()); +function f(i) { + if ("a" in i) { + return i.a; + } + else if ("b" in i) { + return i.b; + } + return "c" in i && i.c; +} diff --git a/tests/baselines/reference/typeGuardOfFromPropNameInUnionType.symbols b/tests/baselines/reference/typeGuardOfFromPropNameInUnionType.symbols index 72fb3df2fc5..93e4c072f44 100644 --- a/tests/baselines/reference/typeGuardOfFromPropNameInUnionType.symbols +++ b/tests/baselines/reference/typeGuardOfFromPropNameInUnionType.symbols @@ -289,3 +289,33 @@ class SelfAssert { } } } + +interface Indexed { +>Indexed : Symbol(Indexed, Decl(typeGuardOfFromPropNameInUnionType.ts, 90, 1)) + + [s: string]: any; +>s : Symbol(s, Decl(typeGuardOfFromPropNameInUnionType.ts, 93, 5)) +} + +function f(i: Indexed) { +>f : Symbol(f, Decl(typeGuardOfFromPropNameInUnionType.ts, 94, 1)) +>i : Symbol(i, Decl(typeGuardOfFromPropNameInUnionType.ts, 96, 11)) +>Indexed : Symbol(Indexed, Decl(typeGuardOfFromPropNameInUnionType.ts, 90, 1)) + + if ("a" in i) { +>i : Symbol(i, Decl(typeGuardOfFromPropNameInUnionType.ts, 96, 11)) + + return i.a; +>i : Symbol(i, Decl(typeGuardOfFromPropNameInUnionType.ts, 96, 11)) + } + else if ("b" in i) { +>i : Symbol(i, Decl(typeGuardOfFromPropNameInUnionType.ts, 96, 11)) + + return i.b; +>i : Symbol(i, Decl(typeGuardOfFromPropNameInUnionType.ts, 96, 11)) + } + return "c" in i && i.c; +>i : Symbol(i, Decl(typeGuardOfFromPropNameInUnionType.ts, 96, 11)) +>i : Symbol(i, Decl(typeGuardOfFromPropNameInUnionType.ts, 96, 11)) +} + diff --git a/tests/baselines/reference/typeGuardOfFromPropNameInUnionType.types b/tests/baselines/reference/typeGuardOfFromPropNameInUnionType.types index 4aff12ae077..8585e09c64a 100644 --- a/tests/baselines/reference/typeGuardOfFromPropNameInUnionType.types +++ b/tests/baselines/reference/typeGuardOfFromPropNameInUnionType.types @@ -316,3 +316,46 @@ class SelfAssert { } } } + +interface Indexed { +>Indexed : Indexed + + [s: string]: any; +>s : string +} + +function f(i: Indexed) { +>f : (i: Indexed) => any +>i : Indexed +>Indexed : Indexed + + if ("a" in i) { +>"a" in i : boolean +>"a" : "a" +>i : Indexed + + return i.a; +>i.a : any +>i : Indexed +>a : any + } + else if ("b" in i) { +>"b" in i : boolean +>"b" : "b" +>i : Indexed + + return i.b; +>i.b : any +>i : Indexed +>b : any + } + return "c" in i && i.c; +>"c" in i && i.c : any +>"c" in i : boolean +>"c" : "c" +>i : Indexed +>i.c : any +>i : Indexed +>c : any +} + diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardOfFromPropNameInUnionType.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardOfFromPropNameInUnionType.ts index d89d7b8c4ef..e1256e42881 100644 --- a/tests/cases/conformance/expressions/typeGuards/typeGuardOfFromPropNameInUnionType.ts +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardOfFromPropNameInUnionType.ts @@ -88,4 +88,18 @@ class SelfAssert { } else { } } -} \ No newline at end of file +} + +interface Indexed { + [s: string]: any; +} + +function f(i: Indexed) { + if ("a" in i) { + return i.a; + } + else if ("b" in i) { + return i.b; + } + return "c" in i && i.c; +}