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
So, I have spend a lot of time on this now, digging around. I am trying to infer a type from a ZodSchema, and have it be a named type, so that I don't get the structure shown on hover, but the name of the type.
Following example, this is how I would expect it to work:
Now, hovering over this_is_dog will only give me the anonymous type:
const this_is_dog: {
name: string;
age: number;
}
I am also using the TypeScript Explorer extension, and it also doesn't show the named type, so I don't think it is a quirk with the hover intellisense.
I have already tried to create a new type intersection with an empty object as recommended in a couple of places, but this didn't have the desired effect.
Now I get DogNew as type on hover. But now of course the type definition of DogNew is useless, because now it will accept any another arbitrary number of extra attributes.
It seems to me, that z.infer<> somehow "breaks" the naming of the type with JSDoc, which can only be healed when intersected with another type, which can't be an empty object, which then again defeats the purpose of having the type in the first place.
Am I missing something here?
The text was updated successfully, but these errors were encountered:
So, I have spend a lot of time on this now, digging around. I am trying to infer a type from a ZodSchema, and have it be a named type, so that I don't get the structure shown on hover, but the name of the type.
Following example, this is how I would expect it to work:
Here, hovering over
this_is_dog
will show me the named type ofOldDog
:const this_is_dog: DogOld
So far, so expected.
Now, if I try to infer the type from the Zod-schema, and try to name it, like this:
Now, hovering over
this_is_dog
will only give me the anonymous type:I am also using the TypeScript Explorer extension, and it also doesn't show the named type, so I don't think it is a quirk with the hover intellisense.
I have already tried to create a new type intersection with an empty object as recommended in a couple of places, but this didn't have the desired effect.
What does work, is this however:
Now I get
DogNew
as type on hover. But now of course the type definition ofDogNew
is useless, because now it will accept any another arbitrary number of extra attributes.It seems to me, that z.infer<> somehow "breaks" the naming of the type with JSDoc, which can only be healed when intersected with another type, which can't be an empty object, which then again defeats the purpose of having the type in the first place.
Am I missing something here?
The text was updated successfully, but these errors were encountered: