Как использовать InjectIntl ​​из реагировать-Intl и TypeScript вместе? - PullRequest
1 голос
/ 07 марта 2019

Я пытаюсь использовать injectIntl из react-intl с такой машинописью, как это (что соответствует тому, что я нашел в ответах на другие вопросы):

import { injectIntl, InjectedIntlProps } from "react-intl";

interface Props {
    certificate?: Certificate;
    onCancelClick(event: any): void;
    onDeleteClick(event: any): void;
    onSubmit(certificate: CertificateWritable): Promise<any>;
}

class CertificateForm extends Component<Props & InjectedIntlProps> {
// ... removed for simplicity
}

export default injectIntl<Props>(CertificateForm);

Но я получаюследующая ошибка:

Error:(174, 34) TS2345: Argument of type 'typeof CertificateForm' is not assignable to parameter of type 'ComponentType<Props & InjectedIntlProps>'.
  Type 'typeof CertificateForm' is not assignable to type 'ComponentClass<Props & InjectedIntlProps, any>'.
    Types of property 'propTypes' are incompatible.
      Type '{ certificate: Requireable<InferProps<{ [x: string]: Requireable<string> | Validator<ReactText> | Requireable<boolean>; }>>; onCancelClick: Validator<(...args: any[]) => any>; onDeleteClick: Requireable<...>; onSubmit: Validator<...>; }' is not assignable to type 'WeakValidationMap<Props & InjectedIntlProps>'.
        Types of property 'certificate' are incompatible.
          Type 'Requireable<InferProps<{ [x: string]: Requireable<string> | Validator<ReactText> | Requireable<boolean>; }>>' is not assignable to type 'Validator<Certificate | null | undefined>'.
            Types of property '[nominalTypeHack]' are incompatible.
              Type 'InferProps<{ [x: string]: Requireable<string> | Validator<ReactText> | Requireable<boolean>; }> | null | undefined' is not assignable to type 'Certificate | null | undefined'.
                Type 'InferProps<{ [x: string]: Requireable<string> | Validator<ReactText> | Requireable<boolean>; }>' is not assignable to type 'Certificate | null | undefined'.
                  Type 'InferProps<{ [x: string]: Requireable<string> | Validator<ReactText> | Requireable<boolean>; }>' is missing the following properties from type 'Certificate': id, caCertificate, caCertificateKey, domain, and 2 more.

Я не понимаю, что я делаю неправильно и как заставить это работать с TS?

Ни одно из предложенных здесь решений не работает: React-intl, используйте API с Typescript

У меня установлена ​​@types/react-intl версия 2.3.17.

Обновление: вот сообщение об ошибке, которое я получаю, если удаляю certificate с Props:

Error:(175, 27) TS2345: Argument of type 'typeof CertificateForm' is not assignable to parameter of type 'ComponentType<Props & InjectedIntlProps>'.
  Type 'typeof CertificateForm' is not assignable to type 'ComponentClass<Props & InjectedIntlProps, any>'.
    Types of property 'propTypes' are incompatible.
      Type '{ certificate: Requireable<InferProps<{ [x: string]: Requireable<string> | Validator<ReactText> | Requireable<boolean>; }>>; onCancelClick: Validator<(...args: any[]) => any>; onDeleteClick: Requireable<...>; onSubmit: Validator<...>; }' is not assignable to type 'WeakValidationMap<Props & InjectedIntlProps>'.
        Types of property 'onDeleteClick' are incompatible.
          Type 'Requireable<(...args: any[]) => any>' is not assignable to type 'Validator<(event: any) => void>'.
            Types of property '[nominalTypeHack]' are incompatible.
              Type '((...args: any[]) => any) | null | undefined' is not assignable to type '((event: any) => void) | undefined'.
                Type 'null' is not assignable to type '((event: any) => void) | undefined'.

Версия TypeScript: 3.3.3333

1 Ответ

0 голосов
/ 07 марта 2019

кажется, проблема не в react-intl.Проблема с неверным типом certificate проп.Взгляните на тип Certificate.

Просто удалите certificate из реквизита и проверьте, не исчезла ли проблема.

...