【问题标题】:Type '{ percentage: number; }' is not assignable React Typescript for the CircularProgressbar输入'{百分比:数字; }' 不可为 CircularProgressbar 分配 React Typescript
【发布时间】:2019-05-08 10:10:29
【问题描述】:

您好,我将在我的应用程序中使用 React CircularProgressbar。我按照以下链接中提到的步骤进行操作。

https://github.com/kevinsqi/react-circular-progressbar

我正在使用 Typescript 创建组件,但我收到如下错误和代码。非常感谢。

import * as React from 'react';
import CircularProgressbar from 'react-circular-progressbar';
import 'react-circular-progressbar/dist/styles.css';
 export default function CircularProgressBar(props: {percentageVal: number, textVal: string}) {  

  return (<div>    
    <CircularProgressbar
      percentage={props.percentageVal}
      text={props.textVal}
    />
    </div>);
}

错误:语义错误 TS2322 Type '{ percent: number;文本:字符串; }' 不可分配给类型 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly'

【问题讨论】:

    标签: reactjs typescript progress-bar react-bootstrap


    【解决方案1】:

    我是 react-circular-progressbar 的作者 - 很抱歉您遇到了问题。根据道具,我假设您使用的是 react-circular-progressbar 的 1.x.x 版本?

    这是一个使用 v1.2.1 的 react + typescript CodeSandbox,并且可以使用您正在使用的代码进行编译而不会出现相同的错误:https://codesandbox.io/s/reactcircularprogressbar-stackoverflow-56038279-v121-cris9

    您能否在 CodeSandbox 或小型 typescript create-react-app 存储库中重现该错误?对诊断问题非常有帮助。您也可以尝试更新到 v2.0.0。

    【讨论】:

    • 感谢您的回复,我使用了不同的一种 svg 格式的圆形进度条。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 2014-04-01
    • 1970-01-01
    相关资源
    最近更新 更多