|
| 1 | +=== tests/cases/conformance/types/union/unionTypeIndexSignature.ts === |
| 2 | +var numOrDate: number | Date; |
| 3 | +>numOrDate : number | Date |
| 4 | +>Date : Date |
| 5 | + |
| 6 | +var anyVar: number; |
| 7 | +>anyVar : number |
| 8 | + |
| 9 | +// If each type in U has a string index signature, |
| 10 | +// U has a string index signature of a union type of the types of the string index signatures from each type in U. |
| 11 | + |
| 12 | +var unionOfDifferentReturnType: { [a: string]: number; } | { [a: string]: Date; }; |
| 13 | +>unionOfDifferentReturnType : { [x: string]: number; } | { [x: string]: Date; } |
| 14 | +>a : string |
| 15 | +>a : string |
| 16 | +>Date : Date |
| 17 | + |
| 18 | +numOrDate = unionOfDifferentReturnType["hello"]; // number | Date |
| 19 | +>numOrDate = unionOfDifferentReturnType["hello"] : number | Date |
| 20 | +>numOrDate : number | Date |
| 21 | +>unionOfDifferentReturnType["hello"] : number | Date |
| 22 | +>unionOfDifferentReturnType : { [x: string]: number; } | { [x: string]: Date; } |
| 23 | + |
| 24 | +numOrDate = unionOfDifferentReturnType[10]; // number | Date |
| 25 | +>numOrDate = unionOfDifferentReturnType[10] : number | Date |
| 26 | +>numOrDate : number | Date |
| 27 | +>unionOfDifferentReturnType[10] : number | Date |
| 28 | +>unionOfDifferentReturnType : { [x: string]: number; } | { [x: string]: Date; } |
| 29 | + |
| 30 | +var unionOfTypesWithAndWithoutStringSignature: { [a: string]: number; } | boolean; |
| 31 | +>unionOfTypesWithAndWithoutStringSignature : boolean | { [x: string]: number; } |
| 32 | +>a : string |
| 33 | + |
| 34 | +anyVar = unionOfTypesWithAndWithoutStringSignature["hello"]; // any |
| 35 | +>anyVar = unionOfTypesWithAndWithoutStringSignature["hello"] : any |
| 36 | +>anyVar : number |
| 37 | +>unionOfTypesWithAndWithoutStringSignature["hello"] : any |
| 38 | +>unionOfTypesWithAndWithoutStringSignature : boolean | { [x: string]: number; } |
| 39 | + |
| 40 | +anyVar = unionOfTypesWithAndWithoutStringSignature[10]; // any |
| 41 | +>anyVar = unionOfTypesWithAndWithoutStringSignature[10] : any |
| 42 | +>anyVar : number |
| 43 | +>unionOfTypesWithAndWithoutStringSignature[10] : any |
| 44 | +>unionOfTypesWithAndWithoutStringSignature : boolean | { [x: string]: number; } |
| 45 | + |
| 46 | +// If each type in U has a numeric index signature, |
| 47 | +// U has a numeric index signature of a union type of the types of the numeric index signatures from each type in U. |
| 48 | +var unionOfDifferentReturnType1: { [a: number]: number; } | { [a: number]: Date; }; |
| 49 | +>unionOfDifferentReturnType1 : { [x: number]: number; } | { [x: number]: Date; } |
| 50 | +>a : number |
| 51 | +>a : number |
| 52 | +>Date : Date |
| 53 | + |
| 54 | +numOrDate = unionOfDifferentReturnType1["hello"]; // any |
| 55 | +>numOrDate = unionOfDifferentReturnType1["hello"] : any |
| 56 | +>numOrDate : number | Date |
| 57 | +>unionOfDifferentReturnType1["hello"] : any |
| 58 | +>unionOfDifferentReturnType1 : { [x: number]: number; } | { [x: number]: Date; } |
| 59 | + |
| 60 | +numOrDate = unionOfDifferentReturnType1[10]; // number | Date |
| 61 | +>numOrDate = unionOfDifferentReturnType1[10] : number | Date |
| 62 | +>numOrDate : number | Date |
| 63 | +>unionOfDifferentReturnType1[10] : number | Date |
| 64 | +>unionOfDifferentReturnType1 : { [x: number]: number; } | { [x: number]: Date; } |
| 65 | + |
| 66 | +var unionOfTypesWithAndWithoutStringSignature1: { [a: number]: number; } | boolean; |
| 67 | +>unionOfTypesWithAndWithoutStringSignature1 : boolean | { [x: number]: number; } |
| 68 | +>a : number |
| 69 | + |
| 70 | +anyVar = unionOfTypesWithAndWithoutStringSignature1["hello"]; // any |
| 71 | +>anyVar = unionOfTypesWithAndWithoutStringSignature1["hello"] : any |
| 72 | +>anyVar : number |
| 73 | +>unionOfTypesWithAndWithoutStringSignature1["hello"] : any |
| 74 | +>unionOfTypesWithAndWithoutStringSignature1 : boolean | { [x: number]: number; } |
| 75 | + |
| 76 | +anyVar = unionOfTypesWithAndWithoutStringSignature1[10]; // any |
| 77 | +>anyVar = unionOfTypesWithAndWithoutStringSignature1[10] : any |
| 78 | +>anyVar : number |
| 79 | +>unionOfTypesWithAndWithoutStringSignature1[10] : any |
| 80 | +>unionOfTypesWithAndWithoutStringSignature1 : boolean | { [x: number]: number; } |
| 81 | + |
0 commit comments