新手到TypeScript我尝试将JS代码移植到TS,我得到了错误
[ts]
Type '{ current: number; total: number; }' is not assignable to type
'IntrinsicAttributes & Number'.
Type '{ current: number; total: number; }' is not assignable to type
'Number'.
Property 'toFixed' is missing in type '{ current: number; total: number; }'.
(JSX attribute) current: number
功能
function Header(current: number, total: number, question: DEEP_QUESTION){
// console.log("Header " + current.toString());
return (
<div>
<StepBar current={current} total={total} />
<SurveyTheme theme={question.theme} />
</div>
)
//refresh();
}
消息显示在StepBar调用参数上。 StepBar的签名
function StepBar(current: number, total: number) {
这适用于JS
有什么想法吗?
答案 0 :(得分:5)
StepBar应该接受一个props对象,其成员为current和total。
您可以尝试使用以下内容:
OK
答案 1 :(得分:0)
您可以使用FILE_GENERIC_*
泛型来传递道具类型,如下所示:
React.StatelessComponent