File: spreadOverwritesPropertyStrict.types

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 (150 lines) | stat: -rw-r--r-- 4,569 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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
=== tests/cases/conformance/types/spread/spreadOverwritesPropertyStrict.ts ===
declare var ab: { a: number, b: number };
>ab : { a: number; b: number; }
>a : number
>b : number

declare var abq: { a: number, b?: number };
>abq : { a: number; b?: number | undefined; }
>a : number
>b : number | undefined

var unused1 = { b: 1, ...ab } // error
>unused1 : { a: number; b: number; }
>{ b: 1, ...ab } : { a: number; b: number; }
>b : number
>1 : 1
>ab : { a: number; b: number; }

var unused2 = { ...ab, ...ab } // ok, overwritten error doesn't apply to spreads
>unused2 : { a: number; b: number; }
>{ ...ab, ...ab } : { a: number; b: number; }
>ab : { a: number; b: number; }
>ab : { a: number; b: number; }

var unused3 = { b: 1, ...abq } // ok, abq might have b: undefined
>unused3 : { a: number; b: number; }
>{ b: 1, ...abq } : { a: number; b: number; }
>b : number
>1 : 1
>abq : { a: number; b?: number | undefined; }

var unused4 = { ...ab, b: 1 } // ok, we don't care that b in ab is overwritten
>unused4 : { b: number; a: number; }
>{ ...ab, b: 1 } : { b: number; a: number; }
>ab : { a: number; b: number; }
>b : number
>1 : 1

var unused5 = { ...abq, b: 1 } // ok
>unused5 : { b: number; a: number; }
>{ ...abq, b: 1 } : { b: number; a: number; }
>abq : { a: number; b?: number | undefined; }
>b : number
>1 : 1

function g(obj: { x: number | undefined }) {
>g : (obj: {    x: number | undefined;}) => { x: number | undefined; }
>obj : { x: number | undefined; }
>x : number | undefined

    return { x: 1, ...obj }; // ok, obj might have x: undefined
>{ x: 1, ...obj } : { x: number | undefined; }
>x : number
>1 : 1
>obj : { x: number | undefined; }
}
function f(obj: { x: number } | undefined) {
>f : (obj: {    x: number;} | undefined) => { x: number; }
>obj : { x: number; } | undefined
>x : number

    return { x: 1, ...obj }; // ok, obj might be undefined
>{ x: 1, ...obj } : { x: number; }
>x : number
>1 : 1
>obj : { x: number; } | undefined
}
function h(obj: { x: number } | { x: string }) {
>h : (obj: {    x: number;} | {    x: string;}) => { x: number; } | { x: string; }
>obj : { x: number; } | { x: string; }
>x : number
>x : string

    return { x: 1, ...obj } // error
>{ x: 1, ...obj } : { x: number; } | { x: string; }
>x : number
>1 : 1
>obj : { x: number; } | { x: string; }
}
function i(b: boolean, t: { command: string, ok: string }) {
>i : (b: boolean, t: {    command: string;    ok: string;}) => { command: string; ok?: string | undefined; }
>b : boolean
>t : { command: string; ok: string; }
>command : string
>ok : string

    return { command: "hi", ...(b ? t : {}) } // ok
>{ command: "hi", ...(b ? t : {}) } : { command: string; ok?: string | undefined; }
>command : string
>"hi" : "hi"
>(b ? t : {}) : { command: string; ok: string; } | {}
>b ? t : {} : { command: string; ok: string; } | {}
>b : boolean
>t : { command: string; ok: string; }
>{} : {}
}
function j() {
>j : () => { command: string; }

    return { ...{ command: "hi" } , ...{ command: "bye" } } // ok
>{ ...{ command: "hi" } , ...{ command: "bye" } } : { command: string; }
>{ command: "hi" } : { command: string; }
>command : string
>"hi" : "hi"
>{ command: "bye" } : { command: string; }
>command : string
>"bye" : "bye"
}
function k(t: { command: string, ok: string }) {
>k : (t: {    command: string;    ok: string;}) => { command: string; ok: string; spoiler2: boolean; spoiler: boolean; }
>t : { command: string; ok: string; }
>command : string
>ok : string

    return { command: "hi", ...{ spoiler: true }, spoiler2: true, ...t } // error
>{ command: "hi", ...{ spoiler: true }, spoiler2: true, ...t } : { command: string; ok: string; spoiler2: boolean; spoiler: boolean; }
>command : string
>"hi" : "hi"
>{ spoiler: true } : { spoiler: boolean; }
>spoiler : boolean
>true : true
>spoiler2 : boolean
>true : true
>t : { command: string; ok: string; }
}

function l(anyrequired: { a: any }) {
>l : (anyrequired: {    a: any;}) => { a: any; }
>anyrequired : { a: any; }
>a : any

    return { a: 'zzz', ...anyrequired } // error
>{ a: 'zzz', ...anyrequired } : { a: any; }
>a : string
>'zzz' : "zzz"
>anyrequired : { a: any; }
}
function m(anyoptional: { a?: any }) {
>m : (anyoptional: {    a?: any;}) => { a: any; }
>anyoptional : { a?: any; }
>a : any

    return { a: 'zzz', ...anyoptional } // ok
>{ a: 'zzz', ...anyoptional } : { a: any; }
>a : string
>'zzz' : "zzz"
>anyoptional : { a?: any; }
}