File: intersectionPropertyCheck.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (46 lines) | stat: -rw-r--r-- 3,010 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
tests/cases/compiler/intersectionPropertyCheck.ts(1,68): error TS2322: Type '{ x: string; y: number; }' is not assignable to type '{ x: string; }'.
  Object literal may only specify known properties, and 'y' does not exist in type '{ x: string; }'.
tests/cases/compiler/intersectionPropertyCheck.ts(4,5): error TS2322: Type '{ a: { y: string; }; }' is not assignable to type '{ a?: { x?: number | undefined; } | undefined; } & { c?: string | undefined; }'.
  Types of property 'a' are incompatible.
    Type '{ y: string; }' has no properties in common with type '{ x?: number | undefined; }'.
tests/cases/compiler/intersectionPropertyCheck.ts(7,3): error TS2322: Type 'T & { a: boolean; }' is not assignable to type '{ a?: string | undefined; }'.
  Types of property 'a' are incompatible.
    Type 'boolean' is not assignable to type 'string'.
tests/cases/compiler/intersectionPropertyCheck.ts(17,22): error TS2322: Type 'boolean' is not assignable to type 'string[]'.


==== tests/cases/compiler/intersectionPropertyCheck.ts (4 errors) ====
    let obj: { a: { x: string } } & { c: number } = { a: { x: 'hello', y: 2 }, c: 5 };  // Nested excess property
                                                                       ~~~~
!!! error TS2322: Type '{ x: string; y: number; }' is not assignable to type '{ x: string; }'.
!!! error TS2322:   Object literal may only specify known properties, and 'y' does not exist in type '{ x: string; }'.
!!! related TS6500 tests/cases/compiler/intersectionPropertyCheck.ts:1:12: The expected type comes from property 'a' which is declared here on type '{ a: { x: string; }; } & { c: number; }'
    
    declare let wrong: { a: { y: string } };
    let weak: { a?: { x?: number } } & { c?: string } = wrong;  // Nested weak object type
        ~~~~
!!! error TS2322: Type '{ a: { y: string; }; }' is not assignable to type '{ a?: { x?: number | undefined; } | undefined; } & { c?: string | undefined; }'.
!!! error TS2322:   Types of property 'a' are incompatible.
!!! error TS2322:     Type '{ y: string; }' has no properties in common with type '{ x?: number | undefined; }'.
    
    function foo<T extends object>(x: { a?: string }, y: T & { a: boolean }) {
      x = y;  // Mismatched property in source intersection
      ~
!!! error TS2322: Type 'T & { a: boolean; }' is not assignable to type '{ a?: string | undefined; }'.
!!! error TS2322:   Types of property 'a' are incompatible.
!!! error TS2322:     Type 'boolean' is not assignable to type 'string'.
    }
    
    // Repro from #36637
    
    interface Test {
      readonly hi?: string[]
    }
    
    function test<T extends object>(value: T): Test {
      return { ...value, hi: true }
                         ~~
!!! error TS2322: Type 'boolean' is not assignable to type 'string[]'.
!!! related TS6500 tests/cases/compiler/intersectionPropertyCheck.ts:13:12: The expected type comes from property 'hi' which is declared here on type 'Test'
    }