Skip to content

types: setLocale typescript support for added methods #2248

@vinsjo

Description

@vinsjo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions