@@ -194,15 +194,15 @@ type OptionalNestedTest = {
194
194
nested ?: {
195
195
in_left : string ;
196
196
sub_nested ?: {
197
- number ?: number ;
197
+ in_both ?: number ;
198
198
} ;
199
199
} ;
200
200
} ;
201
201
Right : {
202
202
nested : {
203
203
in_right : string ;
204
204
sub_nested : {
205
- number : number ;
205
+ in_both : number ;
206
206
} ;
207
207
} ;
208
208
} ;
@@ -217,7 +217,7 @@ expectTypeOf<OptionalNestedRightIntoLeft>().toEqualTypeOf<{
217
217
in_left : string ; // Subentries are kept in both directions
218
218
in_right : string ;
219
219
sub_nested : { // Optional is ovewritten by Right in subentries
220
- number : number ;
220
+ in_both : number ;
221
221
} ;
222
222
} ;
223
223
} > ( ) ;
@@ -231,21 +231,24 @@ expectTypeOf<OptionalNestedLeftIntoRight>().toEqualTypeOf<{
231
231
in_left : string ; // Subentries are kept in both directions
232
232
in_right : string ;
233
233
sub_nested ?: { // Optional is added by Left in subentries
234
- number ?: number ;
235
- } ;
236
- } ;
234
+ in_both ?: number | undefined ;
235
+ } | undefined ;
236
+ } | undefined ;
237
+ // "| undefined" is added here and the only way to remove it
238
+ // would depend on exactOptionalPropertyTypes and a complex
239
+ // logic which may not worth the effort
237
240
} > ( ) ;
238
241
239
242
// Nested Optional: Optional versus undefined entry
240
243
type OptionalOrUndefinedNestedTest = {
241
244
Left : {
242
245
nested ?: {
243
- string : string ;
246
+ in_left : string ;
244
247
} ;
245
248
} ;
246
249
Right : {
247
250
nested : {
248
- number : number ;
251
+ in_right : number ;
249
252
} | undefined ;
250
253
} ;
251
254
} ;
@@ -256,8 +259,8 @@ type OptionalOrUndefinedNestedRightIntoLeft = MergeDeep<
256
259
> ;
257
260
expectTypeOf < OptionalOrUndefinedNestedRightIntoLeft > ( ) . toEqualTypeOf < {
258
261
nested : { // ? is ovewritten by Right
259
- string : string ;
260
- number : number ;
262
+ in_left : string ;
263
+ in_right : number ;
261
264
} | undefined ; // Undefined is kept in both directions
262
265
} > ( ) ;
263
266
@@ -267,8 +270,8 @@ type OptionalOrUndefinedNestedRightIntoRight = MergeDeep<
267
270
> ;
268
271
expectTypeOf < OptionalOrUndefinedNestedRightIntoRight > ( ) . toEqualTypeOf < {
269
272
nested ?: { // ? is added by Left
270
- string : string ;
271
- number : number ;
273
+ in_left : string ;
274
+ in_right : number ;
272
275
} | undefined ; // Undefined is kept in both directions
273
276
} > ( ) ;
274
277
@@ -294,9 +297,7 @@ expectTypeOf<OptionalAndUndefinedNestedRightIntoLeft>().toEqualTypeOf<{
294
297
nested : {
295
298
in_left : string ;
296
299
in_right : string ;
297
- } ; // Undefined is overwritten by Right
298
- // | undefined;
299
- // TODO Should we preserve the "| undefined" there?
300
+ } ; // "| undefined" is removed by Right
300
301
} > ( ) ;
301
302
302
303
type OptionalAndUndefinedNestedRightIntoRight = MergeDeep <
@@ -307,8 +308,7 @@ expectTypeOf<OptionalAndUndefinedNestedRightIntoRight>().toEqualTypeOf<{
307
308
nested ?: {
308
309
in_left : string ;
309
310
in_right : string ;
310
- } ; // Undefined is not kept as redundant
311
- // TODO is there a way to force the undefined to be there? Should we?
311
+ } | undefined ; // "| undefined" is added by Left
312
312
} > ( ) ;
313
313
314
314
// Test for readonly
0 commit comments