mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Adding numeric index signature to test
This commit is contained in:
@@ -1,13 +1,21 @@
|
||||
tests/cases/compiler/assignmentCompat1.ts(4,1): error TS2322: Type '{ [index: string]: any; }' is not assignable to type '{ one: number; }'.
|
||||
Property 'one' is missing in type '{ [index: string]: any; }'.
|
||||
tests/cases/compiler/assignmentCompat1.ts(6,1): error TS2322: Type '{ [index: number]: any; }' is not assignable to type '{ one: number; }'.
|
||||
Property 'one' is missing in type '{ [index: number]: any; }'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/assignmentCompat1.ts (1 errors) ====
|
||||
var x = {one: 1};
|
||||
var y: {[index:string]: any};
|
||||
|
||||
x = y;
|
||||
==== tests/cases/compiler/assignmentCompat1.ts (2 errors) ====
|
||||
var x = { one: 1 };
|
||||
var y: { [index: string]: any };
|
||||
var z: { [index: number]: any };
|
||||
x = y; // Error
|
||||
~
|
||||
!!! error TS2322: Type '{ [index: string]: any; }' is not assignable to type '{ one: number; }'.
|
||||
!!! error TS2322: Property 'one' is missing in type '{ [index: string]: any; }'.
|
||||
y = x;
|
||||
y = x; // Ok because index signature type is any
|
||||
x = z; // Error
|
||||
~
|
||||
!!! error TS2322: Type '{ [index: number]: any; }' is not assignable to type '{ one: number; }'.
|
||||
!!! error TS2322: Property 'one' is missing in type '{ [index: number]: any; }'.
|
||||
z = x; // Ok because index signature type is any
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
//// [assignmentCompat1.ts]
|
||||
var x = {one: 1};
|
||||
var y: {[index:string]: any};
|
||||
|
||||
x = y;
|
||||
y = x;
|
||||
var x = { one: 1 };
|
||||
var y: { [index: string]: any };
|
||||
var z: { [index: number]: any };
|
||||
x = y; // Error
|
||||
y = x; // Ok because index signature type is any
|
||||
x = z; // Error
|
||||
z = x; // Ok because index signature type is any
|
||||
|
||||
|
||||
//// [assignmentCompat1.js]
|
||||
var x = { one: 1 };
|
||||
var y;
|
||||
x = y;
|
||||
y = x;
|
||||
var z;
|
||||
x = y; // Error
|
||||
y = x; // Ok because index signature type is any
|
||||
x = z; // Error
|
||||
z = x; // Ok because index signature type is any
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
var x = {one: 1};
|
||||
var y: {[index:string]: any};
|
||||
|
||||
x = y;
|
||||
y = x;
|
||||
var x = { one: 1 };
|
||||
var y: { [index: string]: any };
|
||||
var z: { [index: number]: any };
|
||||
x = y; // Error
|
||||
y = x; // Ok because index signature type is any
|
||||
x = z; // Error
|
||||
z = x; // Ok because index signature type is any
|
||||
|
||||
Reference in New Issue
Block a user