【发布时间】:2018-11-08 21:29:54
【问题描述】:
我遇到了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] 类型“{}”不可分配给类型
“只读”。类型“{}”中缺少属性“intl”。
进口废话
我如何理解为什么会出现这种情况,我该如何解决?我不想做<Blah intl={intl} />。
injectIntl 的 index.d.ts 如下所示:
function injectIntl<P>(component: ComponentConstructor<P & InjectedIntlProps>, options?: InjectIntlConfig):
React.ComponentClass<P> & { WrappedComponent: ComponentConstructor<P & InjectedIntlProps> };
我可以通过将接口从扩展 InjectedIntlProps 更改为如下类型来解决此问题:
type IBlahProps = InjectedIntlProps & {
}
但我不知道为什么扩展 InjectedIntlProps 不能解决它。
【问题讨论】:
标签: typescript react-intl