File tree Expand file tree Collapse file tree 3 files changed +37
-12
lines changed Expand file tree Collapse file tree 3 files changed +37
-12
lines changed Original file line number Diff line number Diff line change @@ -34084,11 +34084,7 @@ declare function setTimeout(
34084
34084
34085
34085
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/structuredClone) */
34086
34086
declare function structuredClone<
34087
- const T extends BetterTypeScriptLibInternals.StructuredClone.NeverOrUnknown<
34088
- BetterTypeScriptLibInternals.StructuredClone.StructuredCloneOutput<
34089
- BetterTypeScriptLibInternals.StructuredClone.AvoidCyclicConstraint<T>
34090
- >
34091
- >,
34087
+ const T extends BetterTypeScriptLibInternals.StructuredClone.Constraint<T>,
34092
34088
>(
34093
34089
value: T,
34094
34090
options?: StructuredSerializeOptions,
@@ -34863,7 +34859,13 @@ declare namespace BetterTypeScriptLibInternals {
34863
34859
34864
34860
type AvoidCyclicConstraint<T> = [T] extends [infer R] ? R : never;
34865
34861
34866
- // 上限が不正にきつくなっているのを無視する
34867
34862
type NeverOrUnknown<T> = [T] extends [never] ? never : unknown;
34863
+
34864
+ export type Constraint<T> =
34865
+ BetterTypeScriptLibInternals.StructuredClone.NeverOrUnknown<
34866
+ BetterTypeScriptLibInternals.StructuredClone.StructuredCloneOutput<
34867
+ BetterTypeScriptLibInternals.StructuredClone.AvoidCyclicConstraint<T>
34868
+ >
34869
+ >;
34868
34870
}
34869
34871
}
Original file line number Diff line number Diff line change @@ -176,18 +176,20 @@ declare namespace BetterTypeScriptLibInternals {
176
176
177
177
type AvoidCyclicConstraint < T > = [ T ] extends [ infer R ] ? R : never ;
178
178
179
- // 上限が不正にきつくなっているのを無視する
180
179
type NeverOrUnknown < T > = [ T ] extends [ never ] ? never : unknown ;
180
+
181
+ export type Constraint < T > =
182
+ BetterTypeScriptLibInternals . StructuredClone . NeverOrUnknown <
183
+ BetterTypeScriptLibInternals . StructuredClone . StructuredCloneOutput <
184
+ BetterTypeScriptLibInternals . StructuredClone . AvoidCyclicConstraint < T >
185
+ >
186
+ > ;
181
187
}
182
188
}
183
189
184
190
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/structuredClone) */
185
191
declare function structuredClone <
186
- const T extends BetterTypeScriptLibInternals . StructuredClone . NeverOrUnknown <
187
- BetterTypeScriptLibInternals . StructuredClone . StructuredCloneOutput <
188
- BetterTypeScriptLibInternals . StructuredClone . AvoidCyclicConstraint < T >
189
- >
190
- > ,
192
+ const T extends BetterTypeScriptLibInternals . StructuredClone . Constraint < T > ,
191
193
> (
192
194
value : T ,
193
195
options ?: StructuredSerializeOptions ,
Original file line number Diff line number Diff line change @@ -115,4 +115,25 @@ const test = async (url: string) => {
115
115
// @ts -expect-error
116
116
const p = structuredClone ( ( ) => 1 ) ;
117
117
}
118
+ // unions
119
+ {
120
+ function getData ( ) {
121
+ if ( Math . random ( ) > 0.5 ) {
122
+ return { a : 5 , b : null } ;
123
+ } else {
124
+ return { a : null , b : "hello" } ;
125
+ }
126
+ }
127
+ expectType < { a : number ; b : null } | { a : null ; b : string } > (
128
+ structuredClone ( getData ( ) ) ,
129
+ ) ;
130
+ }
131
+ // generic functions
132
+ {
133
+ function func1 <
134
+ T extends BetterTypeScriptLibInternals . StructuredClone . Constraint < T > ,
135
+ > ( obj : T ) {
136
+ return structuredClone ( obj ) ;
137
+ }
138
+ }
118
139
}
You can’t perform that action at this time.
0 commit comments