Adding test

This commit is contained in:
Anders Hejlsberg 2015-10-20 12:40:39 -07:00
parent 6d8950e13c
commit a22f9b87bd
3 changed files with 119 additions and 0 deletions

View file

@ -0,0 +1,66 @@
tests/cases/compiler/objectLiteralExcessProperties.ts(9,18): error TS2322: Type '{ forword: string; }' is not assignable to type 'Book'.
Object literal may only specify known properties, and 'forword' does not exist in type 'Book'.
tests/cases/compiler/objectLiteralExcessProperties.ts(11,27): error TS2322: Type '{ foreward: string; }' is not assignable to type 'Book | string'.
Object literal may only specify known properties, and 'foreward' does not exist in type 'Book | string'.
tests/cases/compiler/objectLiteralExcessProperties.ts(13,53): error TS2322: Type '({ foreword: string; } | { forwards: string; })[]' is not assignable to type 'Book | Book[]'.
Type '({ foreword: string; } | { forwards: string; })[]' is not assignable to type 'Book[]'.
Type '{ foreword: string; } | { forwards: string; }' is not assignable to type 'Book'.
Type '{ forwards: string; }' is not assignable to type 'Book'.
Object literal may only specify known properties, and 'forwards' does not exist in type 'Book'.
tests/cases/compiler/objectLiteralExcessProperties.ts(15,42): error TS2322: Type '{ foreword: string; colour: string; }' is not assignable to type 'Book & Cover'.
Object literal may only specify known properties, and 'colour' does not exist in type 'Book & Cover'.
tests/cases/compiler/objectLiteralExcessProperties.ts(17,26): error TS2322: Type '{ foreward: string; color: string; }' is not assignable to type 'Book & Cover'.
Object literal may only specify known properties, and 'foreward' does not exist in type 'Book & Cover'.
tests/cases/compiler/objectLiteralExcessProperties.ts(19,57): error TS2322: Type '{ foreword: string; color: string; price: number; }' is not assignable to type 'Book & Cover'.
Object literal may only specify known properties, and 'price' does not exist in type 'Book & Cover'.
tests/cases/compiler/objectLiteralExcessProperties.ts(21,43): error TS2322: Type '{ foreword: string; price: number; }' is not assignable to type 'Book & number'.
Object literal may only specify known properties, and 'price' does not exist in type 'Book & number'.
==== tests/cases/compiler/objectLiteralExcessProperties.ts (7 errors) ====
interface Book {
foreword: string;
}
interface Cover {
color?: string;
}
var b1: Book = { forword: "oops" };
~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ forword: string; }' is not assignable to type 'Book'.
!!! error TS2322: Object literal may only specify known properties, and 'forword' does not exist in type 'Book'.
var b2: Book | string = { foreward: "nope" };
~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ foreward: string; }' is not assignable to type 'Book | string'.
!!! error TS2322: Object literal may only specify known properties, and 'foreward' does not exist in type 'Book | string'.
var b3: Book | (Book[]) = [{ foreword: "hello" }, { forwards: "back" }];
~~~~~~~~~~~~~~~~
!!! error TS2322: Type '({ foreword: string; } | { forwards: string; })[]' is not assignable to type 'Book | Book[]'.
!!! error TS2322: Type '({ foreword: string; } | { forwards: string; })[]' is not assignable to type 'Book[]'.
!!! error TS2322: Type '{ foreword: string; } | { forwards: string; }' is not assignable to type 'Book'.
!!! error TS2322: Type '{ forwards: string; }' is not assignable to type 'Book'.
!!! error TS2322: Object literal may only specify known properties, and 'forwards' does not exist in type 'Book'.
var b4: Book & Cover = { foreword: "hi", colour: "blue" };
~~~~~~~~~~~~~~
!!! error TS2322: Type '{ foreword: string; colour: string; }' is not assignable to type 'Book & Cover'.
!!! error TS2322: Object literal may only specify known properties, and 'colour' does not exist in type 'Book & Cover'.
var b5: Book & Cover = { foreward: "hi", color: "blue" };
~~~~~~~~~~~~~~
!!! error TS2322: Type '{ foreward: string; color: string; }' is not assignable to type 'Book & Cover'.
!!! error TS2322: Object literal may only specify known properties, and 'foreward' does not exist in type 'Book & Cover'.
var b6: Book & Cover = { foreword: "hi", color: "blue", price: 10.99 };
~~~~~~~~~~~~
!!! error TS2322: Type '{ foreword: string; color: string; price: number; }' is not assignable to type 'Book & Cover'.
!!! error TS2322: Object literal may only specify known properties, and 'price' does not exist in type 'Book & Cover'.
var b7: Book & number = { foreword: "hi", price: 10.99 };
~~~~~~~~~~~~
!!! error TS2322: Type '{ foreword: string; price: number; }' is not assignable to type 'Book & number'.
!!! error TS2322: Object literal may only specify known properties, and 'price' does not exist in type 'Book & number'.

View file

@ -0,0 +1,32 @@
//// [objectLiteralExcessProperties.ts]
interface Book {
foreword: string;
}
interface Cover {
color?: string;
}
var b1: Book = { forword: "oops" };
var b2: Book | string = { foreward: "nope" };
var b3: Book | (Book[]) = [{ foreword: "hello" }, { forwards: "back" }];
var b4: Book & Cover = { foreword: "hi", colour: "blue" };
var b5: Book & Cover = { foreward: "hi", color: "blue" };
var b6: Book & Cover = { foreword: "hi", color: "blue", price: 10.99 };
var b7: Book & number = { foreword: "hi", price: 10.99 };
//// [objectLiteralExcessProperties.js]
var b1 = { forword: "oops" };
var b2 = { foreward: "nope" };
var b3 = [{ foreword: "hello" }, { forwards: "back" }];
var b4 = { foreword: "hi", colour: "blue" };
var b5 = { foreward: "hi", color: "blue" };
var b6 = { foreword: "hi", color: "blue", price: 10.99 };
var b7 = { foreword: "hi", price: 10.99 };

View file

@ -0,0 +1,21 @@
interface Book {
foreword: string;
}
interface Cover {
color?: string;
}
var b1: Book = { forword: "oops" };
var b2: Book | string = { foreward: "nope" };
var b3: Book | (Book[]) = [{ foreword: "hello" }, { forwards: "back" }];
var b4: Book & Cover = { foreword: "hi", colour: "blue" };
var b5: Book & Cover = { foreward: "hi", color: "blue" };
var b6: Book & Cover = { foreword: "hi", color: "blue", price: 10.99 };
var b7: Book & number = { foreword: "hi", price: 10.99 };