fix: deepMerge type issue for some variables #286
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current deepMerge function is mapping two objects of type
T
.However the fetcherOptions of Context are general fetcherOptions while the variables and what is required by the fetch-function are request specific.
This causes type issues in the generated code. e.g. here in the example project:
Type definition:
According to the type definition, the variables are a type extending the fetcherOptions. This means, the deepMerge signature should be more like
<T, U extends T>(target: T, source: U): U
I tweeked the existing function a bit to use above signature using a cast to the type we want to return. Also added
|| {}
to prevent possible issues with nested calls whenreturnType
might be undefined andreturnType[key]
call would therefore fail.Function could also easily be changed to this signature
<T, U>(target: T, source: U): T & U
but left close to this use case.I also updated the generated files in the example project.