fabian-hiller / valibot

The modular and type safe schema library for validating structural data 🤖
https://valibot.dev
MIT License
5.88k stars 181 forks source link

Make Prettify Type in Valibot Overridable for Better Developer Control #729

Open devcaeg opened 1 month ago

devcaeg commented 1 month ago

728

fabian-hiller commented 1 month ago

Thanks for the implementation! Should we call it valibot instead of valibot/types? Are there any downsides to this change? I need to do some research on my own before merging.

colinhacks commented 1 month ago

Are you sure you're able to override type declarations in this way? In my experiments I get a "Duplicate identifier" error.

devcaeg commented 1 month ago

Thanks for the implementation! Should we call it valibot instead of valibot/types? Are there any downsides to this change? I need to do some research on my own before merging.

In reality there should be no difference.

devcaeg commented 1 month ago

Are you sure you're able to override type declarations in this way? In my experiments I get a "Duplicate identifier" error.

I use this method on several projects and it works well. I do the override in .d.ts files.

devcaeg commented 1 month ago

For example, the adonisjs framework uses this method.

https://docs.adonisjs.com/guides/digging-deeper/emitter#making-events-type-safe

fabian-hiller commented 1 month ago

Thanks for the info and the link. I will try to review it next week.

fabian-hiller commented 1 month ago

For example, the adonisjs framework uses this method.

Do they also use a *.d.ts file internally that can be overwritten by a custom *.d.ts file?

fabian-hiller commented 1 month ago

Have you checked if the following works without modifying Valibot's source code?

// valibot.d.ts
declare module 'valibot' {
 type Prettify<TObject> = TObject;
}
devcaeg commented 1 month ago

Have you checked if the following works without modifying Valibot's source code?

// valibot.d.ts
declare module 'valibot' {
 type Prettify<TObject> = TObject;
}

I have tried this method but it doesn't work for me.

fabian-hiller commented 1 month ago

I have investigated this PR. Your workaround works, but I found one drawback. If Prettify is not defined in a custom *.d.ts file, the Prettify type will no longer be resolved in the type preview:

I expect the preview to show type Input = { email: string } and not type Input = Prettify<…>

screenshot