打字稿:属性“数据”的类型不兼容

时间:2018-11-19 15:18:56

标签: reactjs typescript types dependencies

每个人。我试图解决问题超过4天,但没有结果,所以决定寻求帮助。

我有一个为期一年的项目的副本(不是我的,需要完成它),该副本的构建没有任何错误,但是当我从svn获取资源并运行

  

npm我

在项目中我遇到了错误:属性“数据”的类型不兼容。 我肯定知道原因在node_modules内部,但是无法修复。

我已经尝试通过npm shrinkwrap从工作副本生成package.json,使用npm-collect,手动安装所有必需的软件包。还要尝试将typeRoots添加到tsconfig.json-什么都没有。

第一个组件

const renderContent = (
  widget: IDashboardWidget,
  data: IDashboardWidgetData | INodeInfoData,
) => {
  ...
  const {type: type, displayOptions, thresholds = [], id} = widget;
  {
    console.log(data);
    return <Chart id={id} displayOptions={displayOptions} type={type} data={data} thresholds={thresholds}/>;
  }
  ...
};

export default renderContent;

在第二个组件中将道具用于图表的接口

interface IComponetProps {
  id: string;
  type: WidgetType;
  thresholds?: Array<{
    value: number;
    severity: string;
  }>;
  displayOptions: IDashboardWidgetDisplayOptions,
  data: object[];
}

错误

    Type '{ id: string; displayOptions: IDashboardWidgetDisplayOptions; type: WidgetType.line | WidgetType....' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<Pick<Pick<IChartProps, "data" | "locatio...'.
  Type '{ id: string; displayOptions: IDashboardWidgetDisplayOptions; type: WidgetType.line | WidgetType....' is not assignable to type 'Readonly<Pick<Pick<IChartProps, "data" | "location" | "history" | "match" | "staticContext" | "id...'.
    Types of property 'data' are incompatible.
      Type 'INodeInfoData | { name: string; lat?: string | undefined; lon?: string | undefined; status?: stri...' is not assignable to type 'object[]'.
        Type 'INodeInfoData' is not assignable to type 'object[]'.
          Property 'push' is missing in type 'INodeInfoData'.

devDependencies:

"devDependencies": {
"@fortawesome/fontawesome": "^1.1.8",
"@types/classnames": "^2.2.3",
"@types/cytoscape": "^3.1.9",
"@types/file-saver": "^1.3.0",
"@types/globalize": "0.0.32",
"@types/highcharts": "^5.0.22",
"@types/jest": "^22.2.3",
"@types/jwt-decode": "^2.2.1",
"@types/lodash": "^4.14.109",
"@types/node": "^9.6.18",
"@types/ramda": "^0.25.29",
"@types/react": "^16.3.14",
"@types/react-click-outside": "^3.0.1",
"@types/react-custom-scrollbars": "^4.0.3",
"@types/react-dates": "^16.0.6",
"@types/react-dom": "^16.0.5",
"@types/react-grid-layout": "^0.16.4",
"@types/react-redux": "^5.0.20",
"@types/react-router-dom": "^4.2.6",
"@types/react-router-redux": "^5.0.14",
"@types/react-sortable-hoc": "^0.6.3",
"@types/react-tabs": "^1.0.4",
"@types/react-toggle": "^4.0.1",
"@types/react-widgets": "^4.1.2",
"@types/recompose": "^0.26.1",
"@types/redux-form": "^7.2.5",
"@types/redux-logger": "^3.0.6",
"@types/socket.io-client": "^1.4.32",
"@types/uuid": "^3.4.3",
"globalize-webpack-plugin": "^2.1.0",
"node-sass": "^4.9.0",
"prettier": "^1.12.1",
"redux-devtools-extension": "^2.13.2",
"redux-logger": "^3.0.6",
"sass-loader": "^7.0.1",
"tslint-config-prettier": "^1.13.0",
"typescript": "2.8.3",
"webpack-bundle-analyzer": "^2.13.1"

},

反应:

"react": "^16.3.2"

我几乎可以肯定,依赖关系存在问题,但是我可能是错的。感谢您的任何建议和帮助。

2 个答案:

答案 0 :(得分:1)

似乎INodeInfoData不是数组,因此不能作为object []传递。更多信息将不胜感激。

答案 1 :(得分:0)

好吧,我停止了React 16.3.2和Typescript 2.8.3版本,但我仍然不知道哪个软件包需要更改源代码,但这会有所帮助:

    return <Chart id={id} displayOptions={displayOptions}  type={widgetType} 
            data={data as IDashboardWidgetData}  thresholds={thresholds}/>;