react-component / field-form

⚡️ React Performance First Form Component
https://field-form.react-component.now.sh/
MIT License
982 stars 266 forks source link

[feat] please export `Validator` related types, and in `antd` #330

Open JounQin opened 3 years ago

JounQin commented 3 years ago

I'd like to write custom validators:

import type { Validator } from 'antd' // or at least `import type { Validator } from 'rc-field-form'`

export const strongPasswordValidator: Validator = (rule, value) => {}
JounQin commented 3 years ago

My current workaround:

import type { RuleObject } from 'antd/lib/form'
import type { StoreValue } from 'antd/lib/form/interface'

/**
 * @see https://github.com/react-component/field-form/issues/330
 */
export type Validator = (
  rule: RuleObject,
  value: StoreValue,
  callback: (error?: string) => void,
) => Promise<void> | void