mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-12 01:48:33 -05:00
Test:in doesn't narrow types with string indexers
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -88,4 +88,18 @@ 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user