jquense / yup

Dead simple Object schema validation
MIT License
22.93k stars 934 forks source link

types: setLocale typescript support for added methods #2248

Open vinsjo opened 1 month ago

vinsjo commented 1 month ago

Describe the bug When adding custom method to schema using addMethod, it's possible to use module augmentation to extend the schema interface (See 'Extending built-in schema with new methods' example).

The same possibility to extend the built-in types referenced in LocaleObject isn't possible since they're not exported from index.ts, which causes typescript validation to fail when trying to pass default messages for added methods to setLocale.

To Reproduce

Example where I'm adding divisibleBy method to number schema: https://codesandbox.io/p/sandbox/muddy-dust-59pzxg?file=%2Fsrc%2FYupNumberExtensionExample.ts

Expected behavior MixedLocale, StringLocale, NumberLocale,DateLocale,ObjectLocale, ArrayLocale, TupleLocale and BooleanLocale interfaces should be exported from src/index.ts (lib/index.d.ts in build output) to support declaration merging and enable using setLocale in a type-safe way for extended methods.