From 6c74b81d7eeb67abf3f17cdcc9f1c858916bdd1f Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 8 Nov 2017 09:50:39 -0800 Subject: [PATCH] Test:narrow properties from string index signatures --- .../reference/controlFlowStringIndex.js | 13 ++++++++++ .../reference/controlFlowStringIndex.symbols | 18 +++++++++++++ .../reference/controlFlowStringIndex.types | 26 +++++++++++++++++++ .../controlFlow/controlFlowStringIndex.ts | 6 +++++ 4 files changed, 63 insertions(+) create mode 100644 tests/baselines/reference/controlFlowStringIndex.js create mode 100644 tests/baselines/reference/controlFlowStringIndex.symbols create mode 100644 tests/baselines/reference/controlFlowStringIndex.types create mode 100644 tests/cases/conformance/controlFlow/controlFlowStringIndex.ts diff --git a/tests/baselines/reference/controlFlowStringIndex.js b/tests/baselines/reference/controlFlowStringIndex.js new file mode 100644 index 00000000000..456ae6afcd4 --- /dev/null +++ b/tests/baselines/reference/controlFlowStringIndex.js @@ -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(); +} diff --git a/tests/baselines/reference/controlFlowStringIndex.symbols b/tests/baselines/reference/controlFlowStringIndex.symbols new file mode 100644 index 00000000000..aad08e48a9b --- /dev/null +++ b/tests/baselines/reference/controlFlowStringIndex.symbols @@ -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, --, --)) +} + diff --git a/tests/baselines/reference/controlFlowStringIndex.types b/tests/baselines/reference/controlFlowStringIndex.types new file mode 100644 index 00000000000..d1722dd6925 --- /dev/null +++ b/tests/baselines/reference/controlFlowStringIndex.types @@ -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 +} + diff --git a/tests/cases/conformance/controlFlow/controlFlowStringIndex.ts b/tests/cases/conformance/controlFlow/controlFlowStringIndex.ts new file mode 100644 index 00000000000..78acf6d654e --- /dev/null +++ b/tests/cases/conformance/controlFlow/controlFlowStringIndex.ts @@ -0,0 +1,6 @@ +// @strict: true +type A = { [index: string]: number | null }; +declare const value: A; +if (value.foo !== null) { + value.foo.toExponential() +}