Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript setLocale method have incorrect inner type #1988

Open
viktor-horacek opened this issue Apr 19, 2023 · 1 comment
Open

Typescript setLocale method have incorrect inner type #1988

viktor-horacek opened this issue Apr 19, 2023 · 1 comment

Comments

@viktor-horacek
Copy link

viktor-horacek commented Apr 19, 2023

Message is declared like this

type Message<Extra extends Record<string, unknown> = any> =
    | string
    | ((params: Extra & MessageParams) => unknown)
    | Record<PropertyKey, unknown>;

But should be like this:

type Message<Extra extends Record<string, unknown> = {}> =
    | string
    | ((params: Extra & MessageParams) => unknown)
    | Record<PropertyKey, unknown>;

Because with any as default, i am getting params type any

setLocale({
    mixed: {
        required: (params) => 
    }
})

Params should be of type MessageParams

@michellocana
Copy link

just in case anyone else need this: i was able to pull MessageParams out of the Message type as a workaround for what i wanted:

type MessageParams = Parameters<Extract<Yup.Message<{}>, Function>>[0]

Yup.setLocale({
  mixed: {
    required(params: MessageParams) {
      console.log(params)                  
    },
  },
})

i can open a PR with the suggested change too, but i'm not sure what the impact of this type change would be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants