File: intersectionsAndOptionalProperties.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 459,116 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (54 lines) | stat: -rw-r--r-- 2,542 bytes parent folder | download | duplicates (4)
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/compiler/intersectionsAndOptionalProperties.ts(5,1): error TS2322: Type '{ a: null; b: string; }' is not assignable to type '{ a?: number | undefined; b: string; }'.
  Types of property 'a' are incompatible.
    Type 'null' is not assignable to type 'number | undefined'.
tests/cases/compiler/intersectionsAndOptionalProperties.ts(6,1): error TS2322: Type '{ a: null; } & { b: string; }' is not assignable to type '{ a?: number | undefined; b: string; }'.
  Types of property 'a' are incompatible.
    Type 'null' is not assignable to type 'number | undefined'.
tests/cases/compiler/intersectionsAndOptionalProperties.ts(19,5): error TS2322: Type 'From' is not assignable to type 'To'.
  Types of property 'field' are incompatible.
    Type 'null' is not assignable to type 'number | undefined'.
tests/cases/compiler/intersectionsAndOptionalProperties.ts(20,5): error TS2322: Type 'null' is not assignable to type 'number | undefined'.


==== tests/cases/compiler/intersectionsAndOptionalProperties.ts (4 errors) ====
    declare let x: { a?: number, b: string };
    declare let y: { a: null, b: string };
    declare let z: { a: null } & { b: string };
    
    x = y;  // Error
    ~
!!! error TS2322: Type '{ a: null; b: string; }' is not assignable to type '{ a?: number | undefined; b: string; }'.
!!! error TS2322:   Types of property 'a' are incompatible.
!!! error TS2322:     Type 'null' is not assignable to type 'number | undefined'.
    x = z;  // Error
    ~
!!! error TS2322: Type '{ a: null; } & { b: string; }' is not assignable to type '{ a?: number | undefined; b: string; }'.
!!! error TS2322:   Types of property 'a' are incompatible.
!!! error TS2322:     Type 'null' is not assignable to type 'number | undefined'.
    
    // Repro from #36604
    
    interface To {
        field?: number;
        anotherField: string;
    }
    
    type From =  { field: null } & Omit<To, 'field'>;
    
    function foo(v: From) {
        let x: To;
        x = v;  // Error
        ~
!!! error TS2322: Type 'From' is not assignable to type 'To'.
!!! error TS2322:   Types of property 'field' are incompatible.
!!! error TS2322:     Type 'null' is not assignable to type 'number | undefined'.
        x.field = v.field; // Error
        ~~~~~~~
!!! error TS2322: Type 'null' is not assignable to type 'number | undefined'.
    }
    
    // Repro from #38348
    
    const yy: number[] & [number, ...number[]] = [1];
    const xx: [number, ...number[]] = yy;