iway1 / react-ts-form

https://react-ts-form.com
MIT License
2.01k stars 35 forks source link

clean: added specific return type for createUniqueFieldSchema #37

Closed W1ckh3ad closed 1 year ago

W1ckh3ad commented 1 year ago

Hello,

I' ve found on my journey to migrate some inconvenience handling types. That's why I added this PR.

NOTE: This won't effect any functions or type errors, just makes it more readable.

const textAreaStringSchema = createUniqueFieldSchema(z.string(), "TextArea2");

// VSCode type examples after hovering 

// before change
const textAreaStringSchema: z.ZodBranded<z.ZodString, "TextArea2"> | z.ZodBranded<z.ZodNumber, "TextArea2"> | z.ZodBranded<z.ZodBoolean, "TextArea2"> | z.ZodBranded<z.ZodDate, "TextArea2"> | ... 11 more ... | z.ZodBranded<...>

// after change 
const textAreaStringSchema: z.ZodBranded<z.ZodString, "TextArea2">

EDIT:

After creating the test file for #38 VSCode throws a ts error:

The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

Applying this change, will fix this.

iway1 commented 1 year ago

Ended up fixing this in a PR made today so I'm gonna close but let me know if there are any other issues.

Thanks!