injectIntl ​​ожидает класс с реквизитом, который включает `intl` - PullRequest
0 голосов
/ 09 ноября 2018

У меня проблема с классом React.ComponentClass Тип класса.

Моя версия TypeScript 2.4.2 -

Мой компонент такой:

import * as React from 'react';
import { injectIntl, InjectedIntlProps } from 'react-intl';

interface IBlahProps extends InjectedIntlProps {

}

class BlahBase extends React.Component<IBlahProps> {

}

const Blah = injectIntl(BlahBase);

export default Blah;

Все это прекрасно работает.

Но когда я потребляю этот компонент, вот так:

render() {
  return <Blah />
}

<Blah /> подчеркнут, говоря скриншот ниже:

[ts] Тип '{}' нельзя назначить типу

Readonly. Свойство intl отсутствует в типе {}.

импорт Blah

Как я могу понять, почему это так, и как я могу это исправить? Я не хочу делать <Blah intl={intl} />.

index.d.ts для injectIntl выглядит так:

function injectIntl<P>(component: ComponentConstructor<P & InjectedIntlProps>, options?: InjectIntlConfig):
        React.ComponentClass<P> & { WrappedComponent: ComponentConstructor<P & InjectedIntlProps> };

Я могу это исправить, изменив интерфейс с расширения InjectedIntlProps на такой тип:

type IBlahProps = InjectedIntlProps & {

}

Но я понятия не имею, почему расширение InjectedIntlProps не исправляет это.

enter image description here

1 Ответ

0 голосов
/ 09 ноября 2018

может есть опечатка?

Я только что проверил ваш пример с машинописью 2.9.2, у меня хорошо работает:

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

interface IBlahProps  {
  intl: InjectedIntl;
}

class BlahBase extends React.Component<IBlahProps> {

}

const Blah = injectIntl(BlahBase);

Обратите внимание const Blah не class Blah

enter image description here

...