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
|
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(18,5): error TS2411: Property '2.0' of type 'number' is not assignable to 'number' index type 'string'.
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(21,5): error TS2411: Property '3.0' of type 'MyNumber' is not assignable to 'number' index type 'string'.
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(50,5): error TS2411: Property '2.0' of type 'number' is not assignable to 'number' index type 'string'.
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(68,5): error TS2411: Property '2.0' of type 'number' is not assignable to 'number' index type 'string'.
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(85,5): error TS2322: Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(88,9): error TS2304: Cannot find name 'Myn'.
==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts (6 errors) ====
// String indexer types constrain the types of named properties in their containing type
interface MyNumber extends Number {
foo: number;
}
class C {
[x: number]: string;
constructor() { } // ok
a: string; // ok
b: number; // ok
c: () => {} // ok
"d": string; // ok
"e": number; // ok
1.0: string; // ok
2.0: number; // error
~~~
!!! error TS2411: Property '2.0' of type 'number' is not assignable to 'number' index type 'string'.
"3.0": string; // ok
"4.0": number; // error
3.0: MyNumber // error
~~~
!!! error TS2411: Property '3.0' of type 'MyNumber' is not assignable to 'number' index type 'string'.
get X() { // ok
return '';
}
set X(v) { } // ok
foo() {
return '';
}
static sa: number; // ok
static sb: string; // ok
static foo() { } // ok
static get X() { // ok
return 1;
}
}
interface I {
[x: number]: string;
a: string; // ok
b: number; // ok
c: () => {} // ok
"d": string; // ok
"e": number; // ok
1.0: string; // ok
2.0: number; // error
~~~
!!! error TS2411: Property '2.0' of type 'number' is not assignable to 'number' index type 'string'.
(): string; // ok
(x): number // ok
foo(): string; // ok
"3.0": string; // ok
"4.0": number; // error
f: MyNumber; // error
}
var a: {
[x: number]: string;
a: string; // ok
b: number; // ok
c: () => {} // ok
"d": string; // ok
"e": number; // ok
1.0: string; // ok
2.0: number; // error
~~~
!!! error TS2411: Property '2.0' of type 'number' is not assignable to 'number' index type 'string'.
(): string; // ok
(x): number // ok
foo(): string; // ok
"3.0": string; // ok
"4.0": number; // error
f: MyNumber; // error
}
// error
var b: { [x: number]: string; } = {
a: '',
b: 1,
c: () => { },
"d": '',
"e": 1,
1.0: '',
2.0: 1,
~~~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
!!! related TS6501 tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts:78:10: The expected type comes from this index signature.
"3.0": '',
"4.0": 1,
f: <Myn>null,
~~~
!!! error TS2304: Cannot find name 'Myn'.
get X() {
return '';
},
set X(v) { },
foo() {
return '';
}
}
|