Card
import * as React from 'react';
interface Props {
title: string;
}
export class Card extends React.Component<Props, null> {
public render() {
return (
<div>
{this.props.title}
</div>
);
}
}
现在由于道具的原因,我必须将这个组件与属性一起使用
title
<Card title="Example" />
我需要用
injectIntl()
从…起
react-intl
,所以
intl
import * as React from 'react';
import {injectIntl} from 'react-intl';
interface Props {
title: string;
}
class Component extends React.Component<Props, null> {
}
export const Card = injectIntl(Component);
现在我可以使用
卡片
不带属性的组件
标题
<Card />
这对于typescript编译器来说似乎很好。也没有运行时错误。我预计编译器会抛出如下错误:
Property 'title' is missing in type '{}'.
这种行为是从哪里来的?为什么是这样?如何解决这个问题?
提前谢谢!