Skip to content

Commit a22f9b8

Browse files
committed
Adding test
1 parent 6d8950e commit a22f9b8

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
tests/cases/compiler/objectLiteralExcessProperties.ts(9,18): error TS2322: Type '{ forword: string; }' is not assignable to type 'Book'.
2+
Object literal may only specify known properties, and 'forword' does not exist in type 'Book'.
3+
tests/cases/compiler/objectLiteralExcessProperties.ts(11,27): error TS2322: Type '{ foreward: string; }' is not assignable to type 'Book | string'.
4+
Object literal may only specify known properties, and 'foreward' does not exist in type 'Book | string'.
5+
tests/cases/compiler/objectLiteralExcessProperties.ts(13,53): error TS2322: Type '({ foreword: string; } | { forwards: string; })[]' is not assignable to type 'Book | Book[]'.
6+
Type '({ foreword: string; } | { forwards: string; })[]' is not assignable to type 'Book[]'.
7+
Type '{ foreword: string; } | { forwards: string; }' is not assignable to type 'Book'.
8+
Type '{ forwards: string; }' is not assignable to type 'Book'.
9+
Object literal may only specify known properties, and 'forwards' does not exist in type 'Book'.
10+
tests/cases/compiler/objectLiteralExcessProperties.ts(15,42): error TS2322: Type '{ foreword: string; colour: string; }' is not assignable to type 'Book & Cover'.
11+
Object literal may only specify known properties, and 'colour' does not exist in type 'Book & Cover'.
12+
tests/cases/compiler/objectLiteralExcessProperties.ts(17,26): error TS2322: Type '{ foreward: string; color: string; }' is not assignable to type 'Book & Cover'.
13+
Object literal may only specify known properties, and 'foreward' does not exist in type 'Book & Cover'.
14+
tests/cases/compiler/objectLiteralExcessProperties.ts(19,57): error TS2322: Type '{ foreword: string; color: string; price: number; }' is not assignable to type 'Book & Cover'.
15+
Object literal may only specify known properties, and 'price' does not exist in type 'Book & Cover'.
16+
tests/cases/compiler/objectLiteralExcessProperties.ts(21,43): error TS2322: Type '{ foreword: string; price: number; }' is not assignable to type 'Book & number'.
17+
Object literal may only specify known properties, and 'price' does not exist in type 'Book & number'.
18+
19+
20+
==== tests/cases/compiler/objectLiteralExcessProperties.ts (7 errors) ====
21+
interface Book {
22+
foreword: string;
23+
}
24+
25+
interface Cover {
26+
color?: string;
27+
}
28+
29+
var b1: Book = { forword: "oops" };
30+
~~~~~~~~~~~~~~~
31+
!!! error TS2322: Type '{ forword: string; }' is not assignable to type 'Book'.
32+
!!! error TS2322: Object literal may only specify known properties, and 'forword' does not exist in type 'Book'.
33+
34+
var b2: Book | string = { foreward: "nope" };
35+
~~~~~~~~~~~~~~~~
36+
!!! error TS2322: Type '{ foreward: string; }' is not assignable to type 'Book | string'.
37+
!!! error TS2322: Object literal may only specify known properties, and 'foreward' does not exist in type 'Book | string'.
38+
39+
var b3: Book | (Book[]) = [{ foreword: "hello" }, { forwards: "back" }];
40+
~~~~~~~~~~~~~~~~
41+
!!! error TS2322: Type '({ foreword: string; } | { forwards: string; })[]' is not assignable to type 'Book | Book[]'.
42+
!!! error TS2322: Type '({ foreword: string; } | { forwards: string; })[]' is not assignable to type 'Book[]'.
43+
!!! error TS2322: Type '{ foreword: string; } | { forwards: string; }' is not assignable to type 'Book'.
44+
!!! error TS2322: Type '{ forwards: string; }' is not assignable to type 'Book'.
45+
!!! error TS2322: Object literal may only specify known properties, and 'forwards' does not exist in type 'Book'.
46+
47+
var b4: Book & Cover = { foreword: "hi", colour: "blue" };
48+
~~~~~~~~~~~~~~
49+
!!! error TS2322: Type '{ foreword: string; colour: string; }' is not assignable to type 'Book & Cover'.
50+
!!! error TS2322: Object literal may only specify known properties, and 'colour' does not exist in type 'Book & Cover'.
51+
52+
var b5: Book & Cover = { foreward: "hi", color: "blue" };
53+
~~~~~~~~~~~~~~
54+
!!! error TS2322: Type '{ foreward: string; color: string; }' is not assignable to type 'Book & Cover'.
55+
!!! error TS2322: Object literal may only specify known properties, and 'foreward' does not exist in type 'Book & Cover'.
56+
57+
var b6: Book & Cover = { foreword: "hi", color: "blue", price: 10.99 };
58+
~~~~~~~~~~~~
59+
!!! error TS2322: Type '{ foreword: string; color: string; price: number; }' is not assignable to type 'Book & Cover'.
60+
!!! error TS2322: Object literal may only specify known properties, and 'price' does not exist in type 'Book & Cover'.
61+
62+
var b7: Book & number = { foreword: "hi", price: 10.99 };
63+
~~~~~~~~~~~~
64+
!!! error TS2322: Type '{ foreword: string; price: number; }' is not assignable to type 'Book & number'.
65+
!!! error TS2322: Object literal may only specify known properties, and 'price' does not exist in type 'Book & number'.
66+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//// [objectLiteralExcessProperties.ts]
2+
interface Book {
3+
foreword: string;
4+
}
5+
6+
interface Cover {
7+
color?: string;
8+
}
9+
10+
var b1: Book = { forword: "oops" };
11+
12+
var b2: Book | string = { foreward: "nope" };
13+
14+
var b3: Book | (Book[]) = [{ foreword: "hello" }, { forwards: "back" }];
15+
16+
var b4: Book & Cover = { foreword: "hi", colour: "blue" };
17+
18+
var b5: Book & Cover = { foreward: "hi", color: "blue" };
19+
20+
var b6: Book & Cover = { foreword: "hi", color: "blue", price: 10.99 };
21+
22+
var b7: Book & number = { foreword: "hi", price: 10.99 };
23+
24+
25+
//// [objectLiteralExcessProperties.js]
26+
var b1 = { forword: "oops" };
27+
var b2 = { foreward: "nope" };
28+
var b3 = [{ foreword: "hello" }, { forwards: "back" }];
29+
var b4 = { foreword: "hi", colour: "blue" };
30+
var b5 = { foreward: "hi", color: "blue" };
31+
var b6 = { foreword: "hi", color: "blue", price: 10.99 };
32+
var b7 = { foreword: "hi", price: 10.99 };
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
interface Book {
2+
foreword: string;
3+
}
4+
5+
interface Cover {
6+
color?: string;
7+
}
8+
9+
var b1: Book = { forword: "oops" };
10+
11+
var b2: Book | string = { foreward: "nope" };
12+
13+
var b3: Book | (Book[]) = [{ foreword: "hello" }, { forwards: "back" }];
14+
15+
var b4: Book & Cover = { foreword: "hi", colour: "blue" };
16+
17+
var b5: Book & Cover = { foreward: "hi", color: "blue" };
18+
19+
var b6: Book & Cover = { foreword: "hi", color: "blue", price: 10.99 };
20+
21+
var b7: Book & number = { foreword: "hi", price: 10.99 };

0 commit comments

Comments
 (0)