File: intersectionsAndOptionalProperties.types

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 (76 lines) | stat: -rw-r--r-- 1,552 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
=== tests/cases/compiler/intersectionsAndOptionalProperties.ts ===
declare let x: { a?: number, b: string };
>x : { a?: number | undefined; b: string; }
>a : number | undefined
>b : string

declare let y: { a: null, b: string };
>y : { a: null; b: string; }
>a : null
>null : null
>b : string

declare let z: { a: null } & { b: string };
>z : { a: null; } & { b: string; }
>a : null
>null : null
>b : string

x = y;  // Error
>x = y : { a: null; b: string; }
>x : { a?: number | undefined; b: string; }
>y : { a: null; b: string; }

x = z;  // Error
>x = z : { a: null; } & { b: string; }
>x : { a?: number | undefined; b: string; }
>z : { a: null; } & { b: string; }

// Repro from #36604

interface To {
    field?: number;
>field : number | undefined

    anotherField: string;
>anotherField : string
}

type From =  { field: null } & Omit<To, 'field'>;
>From : { field: null; } & Omit<To, "field">
>field : null
>null : null

function foo(v: From) {
>foo : (v: From) => void
>v : From

    let x: To;
>x : To

    x = v;  // Error
>x = v : From
>x : To
>v : From

    x.field = v.field; // Error
>x.field = v.field : null
>x.field : number | undefined
>x : To
>field : number | undefined
>v.field : null
>v : From
>field : null
}

// Repro from #38348

const yy: number[] & [number, ...number[]] = [1];
>yy : number[] & [number, ...number[]]
>[1] : [number]
>1 : 1

const xx: [number, ...number[]] = yy;
>xx : [number, ...number[]]
>yy : number[] & [number, ...number[]]