简体   繁体   English

TypeScript错误:类型“…”不能分配给类型“ IntrinsicAttributes&Number”

[英]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.

相关问题 与 TypeScript 反应:类型不可分配给类型“IntrinsicAttributes” - React with TypeScript: Type is not assignable to type 'IntrinsicAttributes' 样式组件 + typescript:“as”不可分配给类型 IntrinsicAttributes - Styled components + typescript: "as" is not assignable to type IntrinsicAttributes 类型不可分配给类型 IntrinsicAttributes - Type is not assignable to type IntrinsicAttributes Typescript 错误:: 类型“数字”不可分配给类型“从不” - Typescript error :: Type 'number' is not assignable to type 'never' Typescript 错误:类型 'number' 不可分配给类型 'never' - Typescript error:Type 'number' is not assignable to type 'never' 类型错误:类型'{颜色:字符串; 加载:真; css:字符串; 尺寸:数量; }'不可分配给类型'IntrinsicAttributes &amp; LoaderSizeMarginProps' - Type error:Type '{ color: string; loading: true; css: string; size: number; }'is not assignable to type 'IntrinsicAttributes & LoaderSizeMarginProps' React TypeScript 错误:TS2322 - 类型''不可分配给类型'IntrinsicAttributes &amp; String' - React TypeScript Error : TS2322 - Type '' is not assignable to type 'IntrinsicAttributes & String' 输入'{歌曲:任何; }' 不可分配给类型 'IntrinsicAttributes' NEXTJS/Typescript - Type '{ songs: any; }' is not assignable to type 'IntrinsicAttributes' NEXTJS/Typescript 类型 ref 不可分配给类型 IntrinsicAttributes - Type ref is not assignable to type IntrinsicAttributes typescript 错误 - “布尔值”不可分配给类型“数字” - typescript error - 'boolean' is not assignable to type 'number'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM