Tests for union of index signatures:
• 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. • 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.
This commit is contained in:
parent
c2b2c306af
commit
49b5b5ab99
3 changed files with 148 additions and 0 deletions
44
tests/baselines/reference/unionTypeIndexSignature.js
Normal file
44
tests/baselines/reference/unionTypeIndexSignature.js
Normal file
|
@ -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
|
81
tests/baselines/reference/unionTypeIndexSignature.types
Normal file
81
tests/baselines/reference/unionTypeIndexSignature.types
Normal file
|
@ -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; }
|
||||
|
|
@ -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
|
Loading…
Reference in a new issue