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

feat: export locale #936

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

feat: export locale #936

wants to merge 1 commit into from

Conversation

fjc0k
Copy link

@fjc0k fjc0k commented Jun 11, 2020

This is useful for custom method. eg:

import * as yup from 'yup'
import { isChineseMobilePhoneNumber } from '../utils'

yup.setLocale({
  string: {
    chineseMobilePhoneNumber: '${path} must be a Chinese mobile phone number'
  }
})

yup.addMethod(
  yup.string,
  'chineseMobilePhoneNumber',
  function (message = yup.locale.string.chineseMobilePhoneNumber) {
    return this.test(
      'chineseMobilePhoneNumber',
      message,
      isChineseMobilePhoneNumber
    )
  }
)

@tpict
Copy link

tpict commented Oct 15, 2020

You can import this from yup/lib/locale, but that causes issues for TypeScript users because the @types/yup declaration file won't be applied to that module. This PR would fix that issue!

@knicola
Copy link

knicola commented Mar 8, 2024

we can now use defaultLocale ie. yup.defaultLocale.string though the internal locale types, such as StringLocale, are not exported so declaration merging is not working.

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

Successfully merging this pull request may close these issues.

3 participants