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

Better Typescript validation on errorMessages #34

Open
brophdawg11 opened this issue Jan 16, 2023 · 0 comments
Open

Better Typescript validation on errorMessages #34

brophdawg11 opened this issue Jan 16, 2023 · 0 comments
Labels
help wanted Extra attention is needed TypeScript

Comments

@brophdawg11
Copy link
Owner

errorMessages keys should ideally be restricted to ValidityStateKey unioned with keys in customValidations.

let formDefinitions: FormSchema = {
  inputs: {
    name: {
      validationAttrs: { 
        required: true,
      },
    },
    custom: {
      customValidations: {
        isThisThingValid() { ... }
      },
      errorMessages: {
        // ✅ OK since this matches a customValidation
        isThisThingValid: () => { ... }
        // ❌ Should fail because nope is not a ValidityStateKey or a customValidation name
        nope: () => { ... }
      },
    },
  },
  errorMessages: {
    // ✅ OK since this matches a ValidityStateKey
    valueMissing: () => { ... }
    // ❌ Should fail because nope is not a ValidityStateKey or a custom validation name
    nope: () => { ... }
  }
}
@brophdawg11 brophdawg11 added help wanted Extra attention is needed TypeScript labels Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed TypeScript
Projects
None yet
Development

No branches or pull requests

1 participant