From 49b5b5ab994b3e05924947a8eca2ba43d65cf006 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 3 Nov 2014 13:36:06 -0800 Subject: [PATCH] =?UTF-8?q?Tests=20for=20union=20of=20index=20signatures:?= =?UTF-8?q?=20=E2=80=A2=09If=20each=20type=20in=20U=20has=20a=20string=20i?= =?UTF-8?q?ndex=20signature,=20U=20has=20a=20string=20index=20signature=20?= =?UTF-8?q?of=20a=20union=20type=20of=20the=20types=20of=20the=20string=20?= =?UTF-8?q?index=20signatures=20from=20each=20type=20in=20U.=20=E2=80=A2?= =?UTF-8?q?=09If=20each=20type=20in=20U=20has=20a=20numeric=20index=20sign?= =?UTF-8?q?ature,=20U=20has=20a=20numeric=20index=20signature=20of=20a=20u?= =?UTF-8?q?nion=20type=20of=20the=20types=20of=20the=20numeric=20index=20s?= =?UTF-8?q?ignatures=20from=20each=20type=20in=20U.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reference/unionTypeIndexSignature.js | 44 ++++++++++ .../reference/unionTypeIndexSignature.types | 81 +++++++++++++++++++ .../types/union/unionTypeIndexSignature.ts | 23 ++++++ 3 files changed, 148 insertions(+) create mode 100644 tests/baselines/reference/unionTypeIndexSignature.js create mode 100644 tests/baselines/reference/unionTypeIndexSignature.types create mode 100644 tests/cases/conformance/types/union/unionTypeIndexSignature.ts diff --git a/tests/baselines/reference/unionTypeIndexSignature.js b/tests/baselines/reference/unionTypeIndexSignature.js new file mode 100644 index 00000000000..b39a42e76a4 --- /dev/null +++ b/tests/baselines/reference/unionTypeIndexSignature.js @@ -0,0 +1,44 @@ +//// [unionTypeIndexSignature.ts] +var numOrDate: number | Date; +var anyVar: number; + +// If each type in U has a string index signature, +// U has a string index signature of a union type of the types of the string index signatures from each type in U. + +var unionOfDifferentReturnType: { [a: string]: number; } | { [a: string]: Date; }; +numOrDate = unionOfDifferentReturnType["hello"]; // number | Date +numOrDate = unionOfDifferentReturnType[10]; // number | Date + +var unionOfTypesWithAndWithoutStringSignature: { [a: string]: number; } | boolean; +anyVar = unionOfTypesWithAndWithoutStringSignature["hello"]; // any +anyVar = unionOfTypesWithAndWithoutStringSignature[10]; // any + +// If each type in U has a numeric index signature, +// U has a numeric index signature of a union type of the types of the numeric index signatures from each type in U. +var unionOfDifferentReturnType1: { [a: number]: number; } | { [a: number]: Date; }; +numOrDate = unionOfDifferentReturnType1["hello"]; // any +numOrDate = unionOfDifferentReturnType1[10]; // number | Date + +var unionOfTypesWithAndWithoutStringSignature1: { [a: number]: number; } | boolean; +anyVar = unionOfTypesWithAndWithoutStringSignature1["hello"]; // any +anyVar = unionOfTypesWithAndWithoutStringSignature1[10]; // any + +//// [unionTypeIndexSignature.js] +var numOrDate; +var anyVar; +// If each type in U has a string index signature, +// U has a string index signature of a union type of the types of the string index signatures from each type in U. +var unionOfDifferentReturnType; +numOrDate = unionOfDifferentReturnType["hello"]; // number | Date +numOrDate = unionOfDifferentReturnType[10]; // number | Date +var unionOfTypesWithAndWithoutStringSignature; +anyVar = unionOfTypesWithAndWithoutStringSignature["hello"]; // any +anyVar = unionOfTypesWithAndWithoutStringSignature[10]; // any +// If each type in U has a numeric index signature, +// U has a numeric index signature of a union type of the types of the numeric index signatures from each type in U. +var unionOfDifferentReturnType1; +numOrDate = unionOfDifferentReturnType1["hello"]; // any +numOrDate = unionOfDifferentReturnType1[10]; // number | Date +var unionOfTypesWithAndWithoutStringSignature1; +anyVar = unionOfTypesWithAndWithoutStringSignature1["hello"]; // any +anyVar = unionOfTypesWithAndWithoutStringSignature1[10]; // any diff --git a/tests/baselines/reference/unionTypeIndexSignature.types b/tests/baselines/reference/unionTypeIndexSignature.types new file mode 100644 index 00000000000..96453cffcb4 --- /dev/null +++ b/tests/baselines/reference/unionTypeIndexSignature.types @@ -0,0 +1,81 @@ +=== tests/cases/conformance/types/union/unionTypeIndexSignature.ts === +var numOrDate: number | Date; +>numOrDate : number | Date +>Date : Date + +var anyVar: number; +>anyVar : number + +// If each type in U has a string index signature, +// U has a string index signature of a union type of the types of the string index signatures from each type in U. + +var unionOfDifferentReturnType: { [a: string]: number; } | { [a: string]: Date; }; +>unionOfDifferentReturnType : { [x: string]: number; } | { [x: string]: Date; } +>a : string +>a : string +>Date : Date + +numOrDate = unionOfDifferentReturnType["hello"]; // number | Date +>numOrDate = unionOfDifferentReturnType["hello"] : number | Date +>numOrDate : number | Date +>unionOfDifferentReturnType["hello"] : number | Date +>unionOfDifferentReturnType : { [x: string]: number; } | { [x: string]: Date; } + +numOrDate = unionOfDifferentReturnType[10]; // number | Date +>numOrDate = unionOfDifferentReturnType[10] : number | Date +>numOrDate : number | Date +>unionOfDifferentReturnType[10] : number | Date +>unionOfDifferentReturnType : { [x: string]: number; } | { [x: string]: Date; } + +var unionOfTypesWithAndWithoutStringSignature: { [a: string]: number; } | boolean; +>unionOfTypesWithAndWithoutStringSignature : boolean | { [x: string]: number; } +>a : string + +anyVar = unionOfTypesWithAndWithoutStringSignature["hello"]; // any +>anyVar = unionOfTypesWithAndWithoutStringSignature["hello"] : any +>anyVar : number +>unionOfTypesWithAndWithoutStringSignature["hello"] : any +>unionOfTypesWithAndWithoutStringSignature : boolean | { [x: string]: number; } + +anyVar = unionOfTypesWithAndWithoutStringSignature[10]; // any +>anyVar = unionOfTypesWithAndWithoutStringSignature[10] : any +>anyVar : number +>unionOfTypesWithAndWithoutStringSignature[10] : any +>unionOfTypesWithAndWithoutStringSignature : boolean | { [x: string]: number; } + +// If each type in U has a numeric index signature, +// U has a numeric index signature of a union type of the types of the numeric index signatures from each type in U. +var unionOfDifferentReturnType1: { [a: number]: number; } | { [a: number]: Date; }; +>unionOfDifferentReturnType1 : { [x: number]: number; } | { [x: number]: Date; } +>a : number +>a : number +>Date : Date + +numOrDate = unionOfDifferentReturnType1["hello"]; // any +>numOrDate = unionOfDifferentReturnType1["hello"] : any +>numOrDate : number | Date +>unionOfDifferentReturnType1["hello"] : any +>unionOfDifferentReturnType1 : { [x: number]: number; } | { [x: number]: Date; } + +numOrDate = unionOfDifferentReturnType1[10]; // number | Date +>numOrDate = unionOfDifferentReturnType1[10] : number | Date +>numOrDate : number | Date +>unionOfDifferentReturnType1[10] : number | Date +>unionOfDifferentReturnType1 : { [x: number]: number; } | { [x: number]: Date; } + +var unionOfTypesWithAndWithoutStringSignature1: { [a: number]: number; } | boolean; +>unionOfTypesWithAndWithoutStringSignature1 : boolean | { [x: number]: number; } +>a : number + +anyVar = unionOfTypesWithAndWithoutStringSignature1["hello"]; // any +>anyVar = unionOfTypesWithAndWithoutStringSignature1["hello"] : any +>anyVar : number +>unionOfTypesWithAndWithoutStringSignature1["hello"] : any +>unionOfTypesWithAndWithoutStringSignature1 : boolean | { [x: number]: number; } + +anyVar = unionOfTypesWithAndWithoutStringSignature1[10]; // any +>anyVar = unionOfTypesWithAndWithoutStringSignature1[10] : any +>anyVar : number +>unionOfTypesWithAndWithoutStringSignature1[10] : any +>unionOfTypesWithAndWithoutStringSignature1 : boolean | { [x: number]: number; } + diff --git a/tests/cases/conformance/types/union/unionTypeIndexSignature.ts b/tests/cases/conformance/types/union/unionTypeIndexSignature.ts new file mode 100644 index 00000000000..698da7449f4 --- /dev/null +++ b/tests/cases/conformance/types/union/unionTypeIndexSignature.ts @@ -0,0 +1,23 @@ +var numOrDate: number | Date; +var anyVar: number; + +// If each type in U has a string index signature, +// U has a string index signature of a union type of the types of the string index signatures from each type in U. + +var unionOfDifferentReturnType: { [a: string]: number; } | { [a: string]: Date; }; +numOrDate = unionOfDifferentReturnType["hello"]; // number | Date +numOrDate = unionOfDifferentReturnType[10]; // number | Date + +var unionOfTypesWithAndWithoutStringSignature: { [a: string]: number; } | boolean; +anyVar = unionOfTypesWithAndWithoutStringSignature["hello"]; // any +anyVar = unionOfTypesWithAndWithoutStringSignature[10]; // any + +// If each type in U has a numeric index signature, +// U has a numeric index signature of a union type of the types of the numeric index signatures from each type in U. +var unionOfDifferentReturnType1: { [a: number]: number; } | { [a: number]: Date; }; +numOrDate = unionOfDifferentReturnType1["hello"]; // any +numOrDate = unionOfDifferentReturnType1[10]; // number | Date + +var unionOfTypesWithAndWithoutStringSignature1: { [a: number]: number; } | boolean; +anyVar = unionOfTypesWithAndWithoutStringSignature1["hello"]; // any +anyVar = unionOfTypesWithAndWithoutStringSignature1[10]; // any \ No newline at end of file