final-form / react-final-form-html5-validation

A swap-in replacement for 🏁 React Final Form's <Field> component to provide HTML5 Validation
MIT License
56 stars 8 forks source link

Typescript types? #9

Open trejster opened 6 years ago

trejster commented 6 years ago

Any idea where I can get hold of typescript types for this please?

ackvf commented 5 years ago

I tried to work around it in the meantime, since the whole react-final-form is typed, but to no avail. https://stackoverflow.com/questions/54833810/type-an-untyped-package-with-types-from-another-package

devinus commented 5 years ago

Here's what I've got:

declare module 'react-final-form-html5-validation' {
  import { ComponentType } from 'react';
  import { FieldProps } from 'react-final-form';

  interface Props {
    max?: number;
    maxLength?: number;
    min?: number;
    minLength?: number;
    pattern?: string;
    required?: boolean;
    step?: number;
  }

  type MessageValue = string | ((value: any, props: Props) => string);

  interface Messages {
    badInput?: MessageValue;
    patternMismatch?: MessageValue;
    rangeOverflow?: MessageValue;
    rangeUnderflow?: MessageValue;
    stepMismatch?: MessageValue;
    tooLong?: MessageValue;
    tooShort?: MessageValue;
    typeMismatch?: MessageValue;
    valueMissing?: MessageValue;
  }

  export type Html5ValidationFieldProps<FieldValue = any, T extends HTMLElement = any> = FieldProps<
    FieldValue,
    HTMLElement
  > &
    Messages;

  export const Field: ComponentType<Html5ValidationFieldProps>;
}
saiichihashimoto commented 3 years ago

I'd like to revive this, considering that the core packages have types.

saiichihashimoto commented 3 years ago

I'm starting here https://github.com/DefinitelyTyped/DefinitelyTyped/pull/51524