1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
=== tests/cases/compiler/objectLiteralExcessProperties.ts ===
interface Book {
>Book : Symbol(Book, Decl(objectLiteralExcessProperties.ts, 0, 0))
foreword: string;
>foreword : Symbol(Book.foreword, Decl(objectLiteralExcessProperties.ts, 0, 16))
}
interface Cover {
>Cover : Symbol(Cover, Decl(objectLiteralExcessProperties.ts, 2, 1))
color?: string;
>color : Symbol(Cover.color, Decl(objectLiteralExcessProperties.ts, 4, 17))
}
var b1: Book = { forword: "oops" };
>b1 : Symbol(b1, Decl(objectLiteralExcessProperties.ts, 8, 3))
>Book : Symbol(Book, Decl(objectLiteralExcessProperties.ts, 0, 0))
>forword : Symbol(forword, Decl(objectLiteralExcessProperties.ts, 8, 16))
var b2: Book | string = { foreward: "nope" };
>b2 : Symbol(b2, Decl(objectLiteralExcessProperties.ts, 10, 3))
>Book : Symbol(Book, Decl(objectLiteralExcessProperties.ts, 0, 0))
>foreward : Symbol(foreward, Decl(objectLiteralExcessProperties.ts, 10, 25))
var b3: Book | (Book[]) = [{ foreword: "hello" }, { forwards: "back" }];
>b3 : Symbol(b3, Decl(objectLiteralExcessProperties.ts, 12, 3))
>Book : Symbol(Book, Decl(objectLiteralExcessProperties.ts, 0, 0))
>Book : Symbol(Book, Decl(objectLiteralExcessProperties.ts, 0, 0))
>foreword : Symbol(foreword, Decl(objectLiteralExcessProperties.ts, 12, 28))
>forwards : Symbol(forwards, Decl(objectLiteralExcessProperties.ts, 12, 51))
var b4: Book & Cover = { foreword: "hi", colour: "blue" };
>b4 : Symbol(b4, Decl(objectLiteralExcessProperties.ts, 14, 3))
>Book : Symbol(Book, Decl(objectLiteralExcessProperties.ts, 0, 0))
>Cover : Symbol(Cover, Decl(objectLiteralExcessProperties.ts, 2, 1))
>foreword : Symbol(foreword, Decl(objectLiteralExcessProperties.ts, 14, 24))
>colour : Symbol(colour, Decl(objectLiteralExcessProperties.ts, 14, 40))
var b5: Book & Cover = { foreward: "hi", color: "blue" };
>b5 : Symbol(b5, Decl(objectLiteralExcessProperties.ts, 16, 3))
>Book : Symbol(Book, Decl(objectLiteralExcessProperties.ts, 0, 0))
>Cover : Symbol(Cover, Decl(objectLiteralExcessProperties.ts, 2, 1))
>foreward : Symbol(foreward, Decl(objectLiteralExcessProperties.ts, 16, 24))
>color : Symbol(color, Decl(objectLiteralExcessProperties.ts, 16, 40))
var b6: Book & Cover = { foreword: "hi", color: "blue", price: 10.99 };
>b6 : Symbol(b6, Decl(objectLiteralExcessProperties.ts, 18, 3))
>Book : Symbol(Book, Decl(objectLiteralExcessProperties.ts, 0, 0))
>Cover : Symbol(Cover, Decl(objectLiteralExcessProperties.ts, 2, 1))
>foreword : Symbol(foreword, Decl(objectLiteralExcessProperties.ts, 18, 24))
>color : Symbol(color, Decl(objectLiteralExcessProperties.ts, 18, 40))
>price : Symbol(price, Decl(objectLiteralExcessProperties.ts, 18, 55))
var b7: Book & number = { foreword: "hi", price: 10.99 };
>b7 : Symbol(b7, Decl(objectLiteralExcessProperties.ts, 20, 3))
>Book : Symbol(Book, Decl(objectLiteralExcessProperties.ts, 0, 0))
>foreword : Symbol(foreword, Decl(objectLiteralExcessProperties.ts, 20, 25))
>price : Symbol(price, Decl(objectLiteralExcessProperties.ts, 20, 41))
var b8: Cover | Cover[] = { couleur : "non" };
>b8 : Symbol(b8, Decl(objectLiteralExcessProperties.ts, 22, 3))
>Cover : Symbol(Cover, Decl(objectLiteralExcessProperties.ts, 2, 1))
>Cover : Symbol(Cover, Decl(objectLiteralExcessProperties.ts, 2, 1))
>couleur : Symbol(couleur, Decl(objectLiteralExcessProperties.ts, 22, 27))
var b9: Book | Book[] = { forewarned: "still no" };
>b9 : Symbol(b9, Decl(objectLiteralExcessProperties.ts, 24, 3))
>Book : Symbol(Book, Decl(objectLiteralExcessProperties.ts, 0, 0))
>Book : Symbol(Book, Decl(objectLiteralExcessProperties.ts, 0, 0))
>forewarned : Symbol(forewarned, Decl(objectLiteralExcessProperties.ts, 24, 25))
interface Indexed {
>Indexed : Symbol(Indexed, Decl(objectLiteralExcessProperties.ts, 24, 51))
[n: number]: Cover;
>n : Symbol(n, Decl(objectLiteralExcessProperties.ts, 27, 5))
>Cover : Symbol(Cover, Decl(objectLiteralExcessProperties.ts, 2, 1))
}
var b10: Indexed = { 0: { }, '1': { } }; // ok
>b10 : Symbol(b10, Decl(objectLiteralExcessProperties.ts, 30, 3))
>Indexed : Symbol(Indexed, Decl(objectLiteralExcessProperties.ts, 24, 51))
>0 : Symbol(0, Decl(objectLiteralExcessProperties.ts, 30, 20))
>'1' : Symbol('1', Decl(objectLiteralExcessProperties.ts, 30, 28))
var b11: Indexed = { 0: { colour: "blue" } }; // nested object literal still errors
>b11 : Symbol(b11, Decl(objectLiteralExcessProperties.ts, 32, 3))
>Indexed : Symbol(Indexed, Decl(objectLiteralExcessProperties.ts, 24, 51))
>0 : Symbol(0, Decl(objectLiteralExcessProperties.ts, 32, 20))
>colour : Symbol(colour, Decl(objectLiteralExcessProperties.ts, 32, 25))
// Repros inspired by #28752
function test<T extends IFoo>() {
>test : Symbol(test, Decl(objectLiteralExcessProperties.ts, 32, 45))
>T : Symbol(T, Decl(objectLiteralExcessProperties.ts, 36, 14))
// No excess property checks on generic types
const obj1: T = { name: "test" };
>obj1 : Symbol(obj1, Decl(objectLiteralExcessProperties.ts, 38, 9))
>T : Symbol(T, Decl(objectLiteralExcessProperties.ts, 36, 14))
>name : Symbol(name, Decl(objectLiteralExcessProperties.ts, 38, 21))
// No excess property checks on intersections involving generics
const obj2: T & { prop: boolean } = { name: "test", prop: true };
>obj2 : Symbol(obj2, Decl(objectLiteralExcessProperties.ts, 40, 9))
>T : Symbol(T, Decl(objectLiteralExcessProperties.ts, 36, 14))
>prop : Symbol(prop, Decl(objectLiteralExcessProperties.ts, 40, 21))
>name : Symbol(name, Decl(objectLiteralExcessProperties.ts, 40, 41))
>prop : Symbol(prop, Decl(objectLiteralExcessProperties.ts, 40, 55))
// Excess property checks only on non-generic parts of unions
const obj3: T | { prop: boolean } = { name: "test", prop: true };
>obj3 : Symbol(obj3, Decl(objectLiteralExcessProperties.ts, 42, 9))
>T : Symbol(T, Decl(objectLiteralExcessProperties.ts, 36, 14))
>prop : Symbol(prop, Decl(objectLiteralExcessProperties.ts, 42, 21))
>name : Symbol(name, Decl(objectLiteralExcessProperties.ts, 42, 41))
>prop : Symbol(prop, Decl(objectLiteralExcessProperties.ts, 42, 55))
// Excess property checks only on non-generic parts of unions
const obj4: T & { prop: boolean } | { name: string } = { name: "test", prop: true };
>obj4 : Symbol(obj4, Decl(objectLiteralExcessProperties.ts, 44, 9))
>T : Symbol(T, Decl(objectLiteralExcessProperties.ts, 36, 14))
>prop : Symbol(prop, Decl(objectLiteralExcessProperties.ts, 44, 21))
>name : Symbol(name, Decl(objectLiteralExcessProperties.ts, 44, 41))
>name : Symbol(name, Decl(objectLiteralExcessProperties.ts, 44, 60))
>prop : Symbol(prop, Decl(objectLiteralExcessProperties.ts, 44, 74))
// No excess property checks when union includes 'object' type
const obj5: object | { x: string } = { z: 'abc' }
>obj5 : Symbol(obj5, Decl(objectLiteralExcessProperties.ts, 46, 9))
>x : Symbol(x, Decl(objectLiteralExcessProperties.ts, 46, 26))
>z : Symbol(z, Decl(objectLiteralExcessProperties.ts, 46, 42))
// The 'object' type has no effect on intersections
const obj6: object & { x: string } = { z: 'abc' }
>obj6 : Symbol(obj6, Decl(objectLiteralExcessProperties.ts, 48, 9))
>x : Symbol(x, Decl(objectLiteralExcessProperties.ts, 48, 26))
>z : Symbol(z, Decl(objectLiteralExcessProperties.ts, 48, 42))
}
|