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.
Improvements:
Input
andOutput
withInferInput
andInferOutput
in one of the examples.Dependent default values
example to enable TypeScript to infer the correct output type.More information related to the 2nd improvement:
The example without the improvement does not work as intended. This might be because TS does not narrow the type of a generic function parameter (related) but using the ternary operator narrows the type and everything works as intended. There is one major difference between the current and improved examples. The current example returned the same object reference but the improved example doesn't when
sum
is notundefined
and I think it is fine because:transform
action is meant to transform values, so relying on referential equality should be discouraged.