valibot icon indicating copy to clipboard operation
valibot copied to clipboard

Make Prettify Type in Valibot Overridable for Better Developer Control

Open devcaeg opened this issue 1 year ago • 10 comments

#728

devcaeg avatar Jul 18 '24 21:07 devcaeg

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.

fabian-hiller avatar Jul 18 '24 22:07 fabian-hiller

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

colinhacks avatar Jul 24 '24 19:07 colinhacks

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 avatar Jul 24 '24 20:07 devcaeg

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 avatar Jul 24 '24 20:07 devcaeg

For example, the adonisjs framework uses this method.

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

devcaeg avatar Jul 24 '24 20:07 devcaeg

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

fabian-hiller avatar Jul 26 '24 10:07 fabian-hiller

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 avatar Jul 30 '24 14:07 fabian-hiller

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

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

fabian-hiller avatar Jul 30 '24 14:07 fabian-hiller

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.

devcaeg avatar Jul 31 '24 21:07 devcaeg

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

fabian-hiller avatar Aug 01 '24 12:08 fabian-hiller