[英]TypeScript error : Type '…' is not assignable to type 'IntrinsicAttributes & Number'
Newbie to TypeScript I try to port a JS code to TS and I get the error 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
The function 功能
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();
}
The messages appears on the StepBar call parameters. 该消息出现在StepBar调用参数上。 The signature of StepBar
StepBar的签名
function StepBar(current: number, total: number) {
This works in JS 这适用于JS
Any idea ? 任何想法 ?
StepBar should accept a props object with members as current and total. StepBar应该接受一个props对象,其成员为当前成员和总数。
Can you try using something like : 你可以尝试使用类似的东西吗:
function StepBar(props: {current: number, total: number}) { ... }
You can use React.StatelessComponent
generic to pass your prop types as follows: 您可以使用
React.StatelessComponent
泛型来传递prop类型,如下所示:
interface IHeaderProps {
current: number;
total: number;
}
const Header:React.StatelessComponent<IHeaderProps> = (props) => {
return (
...
)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.