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

Possibility to get typescript error type in setGlobalMessage #964

Open
vladshcherbin opened this issue Dec 8, 2024 · 1 comment
Open
Assignees
Labels
enhancement New feature or request

Comments

@vladshcherbin
Copy link
Contributor

vladshcherbin commented Dec 8, 2024

Hey 👋

Wondering if it's somehow possible to get the correct typescript type from issue.type

setGlobalMessage((issue) => {
  switch (issue.type) {
    case 'min_length':
      // issue is of type MinLengthIssue so the issue.requirement is a number
      return `Please enter at least ${issue.requirement} characters`
    default:
      return issue.message
  }
}, 'en')

In the example above the type of issue.requirement is unknown

I've tried this way but it didn't work out:

image

I've also tried to find something like InferIssue<'min_length'> to pass error type there and it also didn't work out 😅

valibot - 1.0.0-beta.9

@fabian-hiller
Copy link
Owner

fabian-hiller commented Dec 8, 2024

Theoretically this is possible, but there might be a problem if users use custom schemas and actions. I will have to think about it.

@fabian-hiller fabian-hiller self-assigned this Dec 8, 2024
@fabian-hiller fabian-hiller added the enhancement New feature or request label Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants