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
|
tests/cases/compiler/indexerConstraints2.ts(9,5): error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'.
tests/cases/compiler/indexerConstraints2.ts(17,5): error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'.
tests/cases/compiler/indexerConstraints2.ts(26,5): error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'.
tests/cases/compiler/indexerConstraints2.ts(46,6): error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
tests/cases/compiler/indexerConstraints2.ts(52,6): error TS1337: An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead.
tests/cases/compiler/indexerConstraints2.ts(58,6): error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
tests/cases/compiler/indexerConstraints2.ts(70,6): error TS1337: An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead.
tests/cases/compiler/indexerConstraints2.ts(74,6): error TS1337: An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead.
tests/cases/compiler/indexerConstraints2.ts(79,5): error TS1021: An index signature must have a type annotation.
==== tests/cases/compiler/indexerConstraints2.ts (9 errors) ====
class A { a: number; }
class B extends A { b: number; }
// Inheritance
class F {
[s: string]: B
}
class G extends F {
[n: number]: A
~~~~~~~~~~~~~~
!!! error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'.
}
// Other way
class H {
[n: number]: A
}
class I extends H {
[s: string]: B
~~~~~~~~~~~~~~
!!! error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'.
}
// With hidden indexer
class J {
[n: number]: {}
}
class K extends J {
[n: number]: A;
~~~~~~~~~~~~~~~
!!! error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'.
[s: string]: B;
}
type AliasedNumber = number;
interface L {
[n: AliasedNumber]: A;
}
type AliasedString = string;
interface M {
[s: AliasedString]: A;
}
type AliasedBoolean = boolean;
interface N {
[b: AliasedBoolean]: A;
~
!!! error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
}
type IndexableUnion = "foo" | "bar";
interface O {
[u: IndexableUnion]: A;
~
!!! error TS1337: An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead.
}
type NonIndexableUnion = boolean | {};
interface P {
[u: NonIndexableUnion]: A;
~
!!! error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
}
type NonIndexableUnion2 = string | number;
interface Q {
[u: NonIndexableUnion2]: A;
}
type NonIndexableUnion3 = "foo" | 42;
interface R {
[u: NonIndexableUnion3]: A;
~
!!! error TS1337: An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead.
}
interface S {
[u: "foo" | "bar"]: A;
~
!!! error TS1337: An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead.
}
type Key = string;
interface T {
[key: Key]
~~~~~~~~~~
!!! error TS1021: An index signature must have a type annotation.
}
|