File: objectLiteralExcessProperties.errors.txt

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (137 lines) | stat: -rw-r--r-- 10,877 bytes parent folder | download
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
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, but 'forword' does not exist in type 'Book'. Did you mean to write 'foreword'?
tests/cases/compiler/objectLiteralExcessProperties.ts(11,27): error TS2322: Type '{ foreward: string; }' is not assignable to type 'string | Book'.
  Object literal may only specify known properties, but 'foreward' does not exist in type 'Book'. Did you mean to write 'foreword'?
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, but 'colour' does not exist in type 'Book & Cover'. Did you mean to write 'color'?
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, but 'foreward' does not exist in type 'Book & Cover'. Did you mean to write 'foreword'?
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,5): error TS2322: Type '{ foreword: string; price: number; }' is not assignable to type 'Book & number'.
  Type '{ foreword: string; price: number; }' is not assignable to type 'number'.
tests/cases/compiler/objectLiteralExcessProperties.ts(23,29): error TS2322: Type '{ couleur: string; }' is not assignable to type 'Cover | Cover[]'.
  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 '{ colour: string; }' is not assignable to type 'Cover'.
  Object literal may only specify known properties, but 'colour' does not exist in type 'Cover'. Did you mean to write 'color'?
tests/cases/compiler/objectLiteralExcessProperties.ts(37,25): error TS2304: Cannot find name 'IFoo'.
tests/cases/compiler/objectLiteralExcessProperties.ts(39,11): error TS2322: Type '{ name: string; }' is not assignable to type 'T'.
tests/cases/compiler/objectLiteralExcessProperties.ts(41,11): error TS2322: Type '{ name: string; prop: boolean; }' is not assignable to type 'T & { prop: boolean; }'.
  Type '{ name: string; prop: boolean; }' is not assignable to type 'T'.
tests/cases/compiler/objectLiteralExcessProperties.ts(43,43): error TS2322: Type '{ name: string; prop: boolean; }' is not assignable to type 'T | { prop: boolean; }'.
  Object literal may only specify known properties, and 'name' does not exist in type '{ prop: boolean; }'.
tests/cases/compiler/objectLiteralExcessProperties.ts(45,76): error TS2322: Type '{ name: string; prop: boolean; }' is not assignable to type '{ name: string; } | (T & { prop: boolean; })'.
  Object literal may only specify known properties, and 'prop' does not exist in type '{ name: string; }'.
tests/cases/compiler/objectLiteralExcessProperties.ts(49,44): error TS2322: Type '{ z: string; }' is not assignable to type 'object & { x: string; }'.
  Object literal may only specify known properties, and 'z' does not exist in type 'object & { x: string; }'.


==== tests/cases/compiler/objectLiteralExcessProperties.ts (16 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, but 'forword' does not exist in type 'Book'. Did you mean to write 'foreword'?
    
    var b2: Book | string = { foreward: "nope" };
                              ~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ foreward: string; }' is not assignable to type 'string | Book'.
!!! error TS2322:   Object literal may only specify known properties, but 'foreward' does not exist in type 'Book'. Did you mean to write 'foreword'?
    
    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, but 'colour' does not exist in type 'Book & Cover'. Did you mean to write 'color'?
    
    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, but 'foreward' does not exist in type 'Book & Cover'. Did you mean to write 'foreword'?
    
    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:   Type '{ foreword: string; price: number; }' is not assignable to type 'number'.
    
    var b8: Cover | Cover[] = { couleur : "non" };
                                ~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ couleur: string; }' is not assignable to type 'Cover | Cover[]'.
!!! error TS2322:   Object literal may only specify known properties, and 'couleur' does not exist in type 'Cover | Cover[]'.
    
    var b9: Book | Book[] = { forewarned: "still no" };
                              ~~~~~~~~~~~~~~~~~~~~~~
!!! 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 '{ colour: string; }' is not assignable to type 'Cover'.
!!! error TS2322:   Object literal may only specify known properties, but 'colour' does not exist in type 'Cover'. Did you mean to write 'color'?
!!! related TS6501 tests/cases/compiler/objectLiteralExcessProperties.ts:28:5: The expected type comes from this index signature.
    
    // Repros inspired by #28752
    
    function test<T extends IFoo>() {
                            ~~~~
!!! error TS2304: Cannot find name 'IFoo'.
        // No excess property checks on generic types
        const obj1: T = { name: "test" };
              ~~~~
!!! error TS2322: Type '{ name: string; }' is not assignable to type 'T'.
        // No excess property checks on intersections involving generics
        const obj2: T & { prop: boolean } = { name: "test", prop: true };
              ~~~~
!!! error TS2322: Type '{ name: string; prop: boolean; }' is not assignable to type 'T & { prop: boolean; }'.
!!! error TS2322:   Type '{ name: string; prop: boolean; }' is not assignable to type 'T'.
        // Excess property checks only on non-generic parts of unions
        const obj3: T | { prop: boolean } = { name: "test", prop: true };
                                              ~~~~~~~~~~~~
!!! error TS2322: Type '{ name: string; prop: boolean; }' is not assignable to type 'T | { prop: boolean; }'.
!!! error TS2322:   Object literal may only specify known properties, and 'name' does not exist in type '{ prop: boolean; }'.
        // Excess property checks only on non-generic parts of unions
        const obj4: T & { prop: boolean } | { name: string } = { name: "test", prop: true };
                                                                               ~~~~~~~~~~
!!! error TS2322: Type '{ name: string; prop: boolean; }' is not assignable to type '{ name: string; } | (T & { prop: boolean; })'.
!!! error TS2322:   Object literal may only specify known properties, and 'prop' does not exist in type '{ name: string; }'.
        // No excess property checks when union includes 'object' type
        const obj5: object | { x: string } = { z: 'abc' }
        // The 'object' type has no effect on intersections
        const obj6: object & { x: string } = { z: 'abc' }
                                               ~~~~~~~~
!!! error TS2322: Type '{ z: string; }' is not assignable to type 'object & { x: string; }'.
!!! error TS2322:   Object literal may only specify known properties, and 'z' does not exist in type 'object & { x: string; }'.
    }