You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem is that the Merge try set optional fields with EnforceOptional, which makes optional only * | undefined fields.
But fields with any other types will stay required.
So, if we rewrite Merge type as:
type Merge<Destination, Source> =
EnforceOptional<
// At this point we set all fields except required as optional
SetOptional<
SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
& SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>,
Exclude<
OptionalKeysOf<PickIndexSignature<Destination> & OmitIndexSignature<Destination>>
| OptionalKeysOf<PickIndexSignature<Source> & OmitIndexSignature<Source>>,
RequiredKeysOf<PickIndexSignature<Source> & OmitIndexSignature<Source>>>>>;
It solves a problem with optional any type fields, but gives "Type instantiation is excessively deep and possibly infinite" error at MergeDeep type in tests:
Variables fooBarTupleSpread and fooBarTupleReplace casts to any type because of this error.
Does anyone have any ideas, how can i fix it?
The text was updated successfully, but these errors were encountered:
center-777
changed the title
Incorrect Merge with optional any field
Incorrect Merge with optional any fields
Mar 25, 2023
Hi!
First of all, sorry for my english 🤷♂️
I found a problem with incorrect merging of types with optional
any
fields.Tested on version
3.7.0
.Current
Merge
type is:and next code gives us type with all required fields:
The problem is that the
Merge
try set optional fields withEnforceOptional
, which makes optional only* | undefined
fields.But fields with any other types will stay required.
So, if we rewrite
Merge
type as:we will get the correct result:
It solves a problem with optional
any
type fields, but gives "Type instantiation is excessively deep and possibly infinite" error atMergeDeep
type in tests:Variables
fooBarTupleSpread
andfooBarTupleReplace
casts toany
type because of this error.Does anyone have any ideas, how can i fix it?
The text was updated successfully, but these errors were encountered: