File: mappedTypesAndObjects.errors.txt

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (54 lines) | stat: -rw-r--r-- 1,673 bytes parent folder | download | duplicates (3)
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
tests/cases/conformance/types/mapped/mappedTypesAndObjects.ts(25,11): error TS2430: Interface 'E1<T>' incorrectly extends interface 'Base'.
  Types of property 'foo' are incompatible.
    Type 'T' is not assignable to type '{ [key: string]: any; }'.


==== tests/cases/conformance/types/mapped/mappedTypesAndObjects.ts (1 errors) ====
    function f1<T>(x: Partial<T>, y: Readonly<T>) {
        let obj: {};
        obj = x;
        obj = y;
    }
    
    function f2<T>(x: Partial<T>, y: Readonly<T>) {
        let obj: { [x: string]: any };
        obj = x;
        obj = y;
    }
    
    function f3<T>(x: Partial<T>) {
        x = {};
    }
    
    // Repro from #12900
    
    interface Base {
        foo: { [key: string]: any };
        bar: any;
        baz: any;
    }
    
    interface E1<T> extends Base {
              ~~
!!! error TS2430: Interface 'E1<T>' incorrectly extends interface 'Base'.
!!! error TS2430:   Types of property 'foo' are incompatible.
!!! error TS2430:     Type 'T' is not assignable to type '{ [key: string]: any; }'.
!!! related TS2208 tests/cases/conformance/types/mapped/mappedTypesAndObjects.ts:25:14: This type parameter might need an `extends { [key: string]: any; }` constraint.
        foo: T;
    }
    
    interface Something { name: string, value: string };
    interface E2 extends Base {
        foo: Partial<Something>;  // or other mapped type
    }
    
    interface E3<T> extends Base {
        foo: Partial<T>; // or other mapped type
    }
    
    // Repro from #13747
    
    class Form<T> {
        private values: {[P in keyof T]?: T[P]} = {}
    }