1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(16,5): error TS2411: Property 'foo4' of type 'boolean' is not assignable to 'string' index type 'string | number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(18,5): error TS2411: Property 'foo6' of type 'Date' is not assignable to 'string' index type 'string | number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(19,5): error TS2411: Property 'foo7' of type 'RegExp' is not assignable to 'string' index type 'string | number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(20,5): error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to 'string' index type 'string | number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(21,5): error TS2411: Property 'foo9' of type 'I8' is not assignable to 'string' index type 'string | number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(22,5): error TS2411: Property 'foo10' of type 'A' is not assignable to 'string' index type 'string | number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(23,5): error TS2411: Property 'foo11' of type 'A2<number>' is not assignable to 'string' index type 'string | number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(24,5): error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to 'string' index type 'string | number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(25,5): error TS2411: Property 'foo13' of type '<T>(x: T) => T' is not assignable to 'string' index type 'string | number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(26,5): error TS2411: Property 'foo14' of type 'typeof f' is not assignable to 'string' index type 'string | number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(27,5): error TS2411: Property 'foo15' of type 'typeof c' is not assignable to 'string' index type 'string | number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(28,5): error TS2411: Property 'foo16' of type 'T' is not assignable to 'string' index type 'string | number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(29,5): error TS2411: Property 'foo17' of type 'Object' is not assignable to 'string' index type 'string | number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(30,5): error TS2411: Property 'foo18' of type '{}' is not assignable to 'string' index type 'string | number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(35,5): error TS2411: Property 'foo2' of type 'string' is not assignable to 'string' index type 'number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(37,5): error TS2411: Property 'foo4' of type 'boolean' is not assignable to 'string' index type 'number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(39,5): error TS2411: Property 'foo6' of type 'Date' is not assignable to 'string' index type 'number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(40,5): error TS2411: Property 'foo7' of type 'RegExp' is not assignable to 'string' index type 'number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(41,5): error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to 'string' index type 'number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(42,5): error TS2411: Property 'foo9' of type 'I8' is not assignable to 'string' index type 'number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(43,5): error TS2411: Property 'foo10' of type 'A' is not assignable to 'string' index type 'number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(44,5): error TS2411: Property 'foo11' of type 'A2<number>' is not assignable to 'string' index type 'number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(45,5): error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to 'string' index type 'number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(46,5): error TS2411: Property 'foo13' of type '<T>(x: T) => T' is not assignable to 'string' index type 'number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(47,5): error TS2411: Property 'foo14' of type 'typeof f' is not assignable to 'string' index type 'number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(48,5): error TS2411: Property 'foo15' of type 'typeof c' is not assignable to 'string' index type 'number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(49,5): error TS2411: Property 'foo16' of type 'T' is not assignable to 'string' index type 'number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(50,5): error TS2411: Property 'foo17' of type 'Object' is not assignable to 'string' index type 'number'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(51,5): error TS2411: Property 'foo18' of type '{}' is not assignable to 'string' index type 'number'.
==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts (29 errors) ====
enum E { e1, e2 }
interface I8 { [x: string]: number[]; }
class A { foo: number; }
class A2<T> { foo: T; }
function f() { }
module f { export var bar = 1; }
class c { baz: string }
module c { export var bar = 1; }
// A type T is a subtype of a union type U if T is a subtype of any type in U.
interface I1<T> {
[x: string]: string | number;
foo: any; // ok
foo2: string; // ok
foo3: number; // ok
foo4: boolean; // error
~~~~
!!! error TS2411: Property 'foo4' of type 'boolean' is not assignable to 'string' index type 'string | number'.
foo5: E; // ok - subtype of number
foo6: Date; // error
~~~~
!!! error TS2411: Property 'foo6' of type 'Date' is not assignable to 'string' index type 'string | number'.
foo7: RegExp; // error
~~~~
!!! error TS2411: Property 'foo7' of type 'RegExp' is not assignable to 'string' index type 'string | number'.
foo8: { bar: number }; // error
~~~~
!!! error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to 'string' index type 'string | number'.
foo9: I8; // error
~~~~
!!! error TS2411: Property 'foo9' of type 'I8' is not assignable to 'string' index type 'string | number'.
foo10: A; // error
~~~~~
!!! error TS2411: Property 'foo10' of type 'A' is not assignable to 'string' index type 'string | number'.
foo11: A2<number>; // error
~~~~~
!!! error TS2411: Property 'foo11' of type 'A2<number>' is not assignable to 'string' index type 'string | number'.
foo12: (x) => number; //error
~~~~~
!!! error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to 'string' index type 'string | number'.
foo13: <T>(x: T) => T; // error
~~~~~
!!! error TS2411: Property 'foo13' of type '<T>(x: T) => T' is not assignable to 'string' index type 'string | number'.
foo14: typeof f; // error
~~~~~
!!! error TS2411: Property 'foo14' of type 'typeof f' is not assignable to 'string' index type 'string | number'.
foo15: typeof c; // error
~~~~~
!!! error TS2411: Property 'foo15' of type 'typeof c' is not assignable to 'string' index type 'string | number'.
foo16: T; // error
~~~~~
!!! error TS2411: Property 'foo16' of type 'T' is not assignable to 'string' index type 'string | number'.
foo17: Object; // error
~~~~~
!!! error TS2411: Property 'foo17' of type 'Object' is not assignable to 'string' index type 'string | number'.
foo18: {}; // error
~~~~~
!!! error TS2411: Property 'foo18' of type '{}' is not assignable to 'string' index type 'string | number'.
}
interface I2<T> {
[x: string]: E | number;
foo: any; // ok
foo2: string; // error
~~~~
!!! error TS2411: Property 'foo2' of type 'string' is not assignable to 'string' index type 'number'.
foo3: number; // ok
foo4: boolean; // error
~~~~
!!! error TS2411: Property 'foo4' of type 'boolean' is not assignable to 'string' index type 'number'.
foo5: E; // ok
foo6: Date; // error
~~~~
!!! error TS2411: Property 'foo6' of type 'Date' is not assignable to 'string' index type 'number'.
foo7: RegExp; // error
~~~~
!!! error TS2411: Property 'foo7' of type 'RegExp' is not assignable to 'string' index type 'number'.
foo8: { bar: number }; // error
~~~~
!!! error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to 'string' index type 'number'.
foo9: I8; // error
~~~~
!!! error TS2411: Property 'foo9' of type 'I8' is not assignable to 'string' index type 'number'.
foo10: A; // error
~~~~~
!!! error TS2411: Property 'foo10' of type 'A' is not assignable to 'string' index type 'number'.
foo11: A2<number>; // error
~~~~~
!!! error TS2411: Property 'foo11' of type 'A2<number>' is not assignable to 'string' index type 'number'.
foo12: (x) => number; //error
~~~~~
!!! error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to 'string' index type 'number'.
foo13: <T>(x: T) => T; // error
~~~~~
!!! error TS2411: Property 'foo13' of type '<T>(x: T) => T' is not assignable to 'string' index type 'number'.
foo14: typeof f; // error
~~~~~
!!! error TS2411: Property 'foo14' of type 'typeof f' is not assignable to 'string' index type 'number'.
foo15: typeof c; // error
~~~~~
!!! error TS2411: Property 'foo15' of type 'typeof c' is not assignable to 'string' index type 'number'.
foo16: T; // error
~~~~~
!!! error TS2411: Property 'foo16' of type 'T' is not assignable to 'string' index type 'number'.
foo17: Object; // error
~~~~~
!!! error TS2411: Property 'foo17' of type 'Object' is not assignable to 'string' index type 'number'.
foo18: {}; // error
~~~~~
!!! error TS2411: Property 'foo18' of type '{}' is not assignable to 'string' index type 'number'.
}
|