Test:narrow properties from string index signatures

This commit is contained in:
Nathan Shively-Sanders
2017-11-08 09:50:39 -08:00
parent d73fb3acdd
commit 6c74b81d7e
4 changed files with 63 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
//// [controlFlowStringIndex.ts]
type A = { [index: string]: number | null };
declare const value: A;
if (value.foo !== null) {
value.foo.toExponential()
}
//// [controlFlowStringIndex.js]
"use strict";
if (value.foo !== null) {
value.foo.toExponential();
}

View File

@@ -0,0 +1,18 @@
=== tests/cases/conformance/controlFlow/controlFlowStringIndex.ts ===
type A = { [index: string]: number | null };
>A : Symbol(A, Decl(controlFlowStringIndex.ts, 0, 0))
>index : Symbol(index, Decl(controlFlowStringIndex.ts, 0, 12))
declare const value: A;
>value : Symbol(value, Decl(controlFlowStringIndex.ts, 1, 13))
>A : Symbol(A, Decl(controlFlowStringIndex.ts, 0, 0))
if (value.foo !== null) {
>value : Symbol(value, Decl(controlFlowStringIndex.ts, 1, 13))
value.foo.toExponential()
>value.foo.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --))
>value : Symbol(value, Decl(controlFlowStringIndex.ts, 1, 13))
>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --))
}

View File

@@ -0,0 +1,26 @@
=== tests/cases/conformance/controlFlow/controlFlowStringIndex.ts ===
type A = { [index: string]: number | null };
>A : A
>index : string
>null : null
declare const value: A;
>value : A
>A : A
if (value.foo !== null) {
>value.foo !== null : boolean
>value.foo : number | null
>value : A
>foo : number | null
>null : null
value.foo.toExponential()
>value.foo.toExponential() : string
>value.foo.toExponential : (fractionDigits?: number | undefined) => string
>value.foo : number
>value : A
>foo : number
>toExponential : (fractionDigits?: number | undefined) => string
}

View File

@@ -0,0 +1,6 @@
// @strict: true
type A = { [index: string]: number | null };
declare const value: A;
if (value.foo !== null) {
value.foo.toExponential()
}