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
I’m using Tagged types in combination with Jsonify-ed types. It seems that tagged types aren’t unwrapped when creating their JSON type.
Am I missing something or is that an option for improvement?
Here’s the sample code that I’m using:
importtype{Tagged,Jsonify}from'type-fest'exporttypeUserId=Tagged<number,'UserId'>classUserextendsBaseModel{declareid: UserId}// then I’m extracting the DTO and DTO-JSON typesexportinterfaceUserDto{id: User['id']}exporttypeUserDtoJson=Jsonify<UserDto>// type UserDtoJson = {// id: UserId; ⚠️ still the tagged type, not the actual type// }
I was hoping the UserDtoJson type would have the following shape:
typeUserDtoJson={id: number;}
Using Unwrapped for the DTO type resolve the expected, unwrapped type from the tagged type:
importtype{UnwrapTagged,Jsonify}from'type-fest'exportinterfaceUserDto{id: UnwrapTagged<User['id']>}exporttypeUserDtoJson=Jsonify<UserDto>// type UserDtoJson = {// id: number; ✅ the expected result// }
Is extending the Jsonify type an option to resolve tagged types and unwrap them automatically?
Upvote & Fund
We're using Polar.sh so you can upvote and help fund this issue.
The funding will be given to active contributors.
Thank you in advance for helping prioritize & fund our backlog.
The text was updated successfully, but these errors were encountered:
I’m using
Tagged
types in combination withJsonify
-ed types. It seems that tagged types aren’t unwrapped when creating their JSON type.Am I missing something or is that an option for improvement?
Here’s the sample code that I’m using:
I was hoping the
UserDtoJson
type would have the following shape:Using
Unwrapped
for the DTO type resolve the expected, unwrapped type from the tagged type:Is extending the
Jsonify
type an option to resolve tagged types and unwrap them automatically?Upvote & Fund
The text was updated successfully, but these errors were encountered: