Add test case for excess checking of numeric properties

This commit is contained in:
Nathan Shively-Sanders 2016-05-25 10:18:49 -07:00
parent 642d6d5407
commit 89fb304eee
3 changed files with 36 additions and 1 deletions

View file

@ -19,9 +19,13 @@ tests/cases/compiler/objectLiteralExcessProperties.ts(23,29): error TS2322: Type
Object literal may only specify known properties, and 'couleur' does not exist in type 'Cover | Cover[]'.
tests/cases/compiler/objectLiteralExcessProperties.ts(25,27): error TS2322: Type '{ forewarned: string; }' is not assignable to type 'Book | Book[]'.
Object literal may only specify known properties, and 'forewarned' does not exist in type 'Book | Book[]'.
tests/cases/compiler/objectLiteralExcessProperties.ts(33,27): error TS2322: Type '{ 0: { colour: string; }; }' is not assignable to type 'Indexed'.
Property '0' is incompatible with index signature.
Type '{ colour: string; }' is not assignable to type 'Cover'.
Object literal may only specify known properties, and 'colour' does not exist in type 'Cover'.
==== tests/cases/compiler/objectLiteralExcessProperties.ts (9 errors) ====
==== tests/cases/compiler/objectLiteralExcessProperties.ts (10 errors) ====
interface Book {
foreword: string;
}
@ -77,4 +81,17 @@ tests/cases/compiler/objectLiteralExcessProperties.ts(25,27): error TS2322: Type
~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ forewarned: string; }' is not assignable to type 'Book | Book[]'.
!!! error TS2322: Object literal may only specify known properties, and 'forewarned' does not exist in type 'Book | Book[]'.
interface Indexed {
[n: number]: Cover;
}
var b10: Indexed = { 0: { }, '1': { } }; // ok
var b11: Indexed = { 0: { colour: "blue" } }; // nested object literal still errors
~~~~~~~~~~~~~~
!!! error TS2322: Type '{ 0: { colour: string; }; }' is not assignable to type 'Indexed'.
!!! error TS2322: Property '0' is incompatible with index signature.
!!! error TS2322: Type '{ colour: string; }' is not assignable to type 'Cover'.
!!! error TS2322: Object literal may only specify known properties, and 'colour' does not exist in type 'Cover'.

View file

@ -24,6 +24,14 @@ var b7: Book & number = { foreword: "hi", price: 10.99 };
var b8: Cover | Cover[] = { couleur : "non" };
var b9: Book | Book[] = { forewarned: "still no" };
interface Indexed {
[n: number]: Cover;
}
var b10: Indexed = { 0: { }, '1': { } }; // ok
var b11: Indexed = { 0: { colour: "blue" } }; // nested object literal still errors
//// [objectLiteralExcessProperties.js]
@ -36,3 +44,5 @@ var b6 = { foreword: "hi", color: "blue", price: 10.99 };
var b7 = { foreword: "hi", price: 10.99 };
var b8 = { couleur: "non" };
var b9 = { forewarned: "still no" };
var b10 = { 0: {}, '1': {} }; // ok
var b11 = { 0: { colour: "blue" } }; // nested object literal still errors

View file

@ -23,3 +23,11 @@ var b7: Book & number = { foreword: "hi", price: 10.99 };
var b8: Cover | Cover[] = { couleur : "non" };
var b9: Book | Book[] = { forewarned: "still no" };
interface Indexed {
[n: number]: Cover;
}
var b10: Indexed = { 0: { }, '1': { } }; // ok
var b11: Indexed = { 0: { colour: "blue" } }; // nested object literal still errors