-
-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Buona sera,
I'm experiencing a TypeScript conflict while deep merging a partial JSON into the original JSON using your latest version 3.2.0.
Error Message
Type 'PartialObjectDeep<VideomailRecorderOptions, { recurseIntoArrays: false; allowUndefinedInNonTupleArrays: false; }>' is not assignable to type 'VideomailRecorderOptions' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Property 'apiUrl' is optional in type 'PartialObjectDeep<VideomailRecorderOptions, { recurseIntoArrays: false; allowUndefinedInNonTupleArrays: false; }>' but required in type 'VideomailRecorderOptions'.
Why should I add undefined to the property apiURL to VideomailRecorderOptions when it must remain defined during a deep merge from a partial one? The target already has it defined and would crash my app. No, thanks.
Code
That code is:
const newOptions: VideomailRecorderOptions = deepmerge({
onlyDefinedProperties: true,
})(state, action.payload);Link:
https://github.com/binarykitchen/videomail-recorder/blob/main/src/features/options/reducers.ts#L15
As you can see, it's Redux, merging the payload back to the original state the immutable way. Only with defined properties.
Steps to reproduce
- Git clone git@github.com:binarykitchen/videomail-recorder.git
npm installnpm run types- Errors in the console ...
Summary
All I am after is just to deep merge partial options in JSON format into the original state in JSON, returning a new JSON.
The partial option typings stem from the original option typings this way:
type PartialVideomailRecorderOptions = PartialDeep<VideomailRecorderOptions>;This PartialDeep helper function comes from the type-fest library, which is well-tested:
https://github.com/sindresorhus/type-fest
Appreciate any feedback.
Grazie 🙇