* Switch index signature storage to 'indexInfos: IndexInfo[]' property * Accept new baselines * Remove another usage of IndexKind enum * Update getIndexedAccessType and resolveMappedTypeMembers * Accept new baselines * Update grammar checking for index signatures * Accept new baselines * Consider all index signatures in mapped types and union types * Accept new baselines * Update getIndexType * Accept new baselines * Intersect multiple applicable index signatures * Use getApplicableIndexInfo instead of hardwired string/number handling * Update index signature relationship checking * Report type for which index signature is missing * Report type for which index signature is missing * Accept new baselines * Make 'number' index signatures consistently apply to numeric strings * Accept new baselines * Update fourslash test * Revise index constraint checking * Accept new baselines * Update error messages * Accept new baselines * Update type inference from index signatures * Update isKnownProperty * Update contextual typing based on index signatures * Accept new baselines * Support union types in index signature declarations * Accept new baselines * Check duplicate index signatures / remove redundant template literals from unions with string * Accept new baselines * Include key type in diagnostic / check symbol-named properties * Accept new baselines * Minor fix * Add tests * Accept new baselines * Add optimized findApplicableIndexInfoForName * Accept new baselines * Another place we don't need to obtain literal type for property name * Accept new baselines * Don't create literal types that are going to be discarded * Individual maps for string, number, bigint, and enum literal types * Remove ineffective optimizations * Accept new baselines * Permit intersections as key types in index signatures * Index expression in element access is template literal context * Add tests * Accept new baselines * Symbol index signatures from object literals with computed symbol properties * Accept new baselines * Add more tests * Accept new baselines * Implement Go To Definition for all applicable index signatures * Add fourslash test * Accept new API baselines
134 lines
5.7 KiB
Plaintext
134 lines
5.7 KiB
Plaintext
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(23,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
|
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(26,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
|
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(36,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
|
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(90,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
|
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(93,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
|
|
|
|
|
==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts (11 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
|
|
~
|
|
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
|
return '';
|
|
}
|
|
set X(v) { } // ok
|
|
~
|
|
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
|
|
|
foo() {
|
|
return '';
|
|
}
|
|
|
|
static sa: number; // ok
|
|
static sb: string; // ok
|
|
|
|
static foo() { } // ok
|
|
static get X() { // ok
|
|
~
|
|
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
|
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() {
|
|
~
|
|
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
|
return '';
|
|
},
|
|
set X(v) { },
|
|
~
|
|
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
|
foo() {
|
|
return '';
|
|
}
|
|
} |