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:
import type { Tagged, Jsonify } from 'type-fest'
export type UserId = Tagged<number, 'UserId'>
class User extends BaseModel {
declare id: UserId
}
// then I’m extracting the DTO and DTO-JSON types
export interface UserDto {
id: User['id']
}
export type UserDtoJson = 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:
type UserDtoJson = {
id: number;
}
Using Unwrapped
for the DTO type resolve the expected, unwrapped type from the tagged type:
import type { UnwrapTagged, Jsonify } from 'type-fest'
export interface UserDto {
id: UnwrapTagged<User['id']>
}
export type UserDtoJson = Jsonify<UserDto>
// type UserDtoJson = {
// id: number; ✅ the expected result
// }
Is extending the Jsonify
type an option to resolve tagged types and unwrap them automatically?
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too