Как использовать injectIntl ​​из react-intl и typescript вместе?

Я пытаюсь использовать 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.


person Honza Kalfus    schedule 07.03.2019    source источник
comment
@cwtuan Спасибо за совет.   -  person Honza Kalfus    schedule 23.04.2019
comment
Быстрое обновление: я переопределил типы, используя файл *.d.ts. Мне кажется, что определение определенно напечатано неверно.   -  person Honza Kalfus    schedule 15.01.2020
comment
Как вы переопределили типы, используя файл *.d.ts, у меня такая же проблема с Typescript 3.5.x   -  person Jun Q    schedule 08.02.2020
comment
@JunQ Вы можете сделать это так: medium.com/@tomsoir/   -  person Honza Kalfus    schedule 08.02.2020


Ответы (1)


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

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

person Dmitry McLygin    schedule 07.03.2019
comment
Это не помогает - если я удалю сертификат из Props, машинописный текст жалуется на следующую опору, я добавил сообщение об ошибке в свой вопрос. - person Honza Kalfus; 07.03.2019
comment
Пожалуйста, добавьте версию TS - person Dmitry McLygin; 07.03.2019
comment
Добавлено к вопросу - person Honza Kalfus; 07.03.2019
comment
не уверен, но попробуйте: ```Компонент‹Props & InjectedIntlProps, любой› ``` - person Dmitry McLygin; 07.03.2019
comment
@HonzaKalfus Я предлагаю вам позвонить. - person Dmitry McLygin; 07.03.2019