fix(client): unwrap constructors to primitives in type mapping#3150
Closed
watersRand wants to merge 3 commits intoredis:masterfrom
Closed
fix(client): unwrap constructors to primitives in type mapping#3150watersRand wants to merge 3 commits intoredis:masterfrom
watersRand wants to merge 3 commits intoredis:masterfrom
Conversation
Collaborator
|
@watersRand thanks for this PR, much appreciated. I will need to check TS performance, as we already have a big issue, so hopefully this doesnt add to it. Will keep in touch. |
Collaborator
|
@watersRand i made a PR with some fixes, please review and merge it, so we can close this one :) |
3df52c8 to
aa815d1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Resolves: #2987
This pull request fixes a type inference bug where using global constructors (like
String,Number, orBoolean) in.withTypeMapping()resulted in incorrect return types, specifically appearing asstring | {}ornumber | {}instead of the expected primitives.The Problem:
When a user provides
String(theStringConstructor) to the mapping, TypeScript'sinferkeyword inReplyWithTypeMappingcaptures the interfaceString(the object wrapper) rather than the primitivestring. Because this interface is a non-null object, it is often represented as{}in type unions, leading to the confusingstring | {}signature for commands likehGet.The Solution:
I introduced an
UnwrapConstructor<T>utility type that explicitly maps global constructors to their primitive counterparts:StringConstructor→stringNumberConstructor→numberBooleanConstructor→booleanBigIntConstructor→bigintThis ensures that the
Extractlogic within the mapping correctly identifies the intended primitive type.Checklist
npm testpass with this change (including linting)?