簡體   English   中英

TS2345 錯誤,但 arguments 應該沒問題?

[英]TS2345 error, but the arguments should be ok?

所以我有這個錯誤:

TS2345: Argument of type '(bounds: any, fill: any, stroke: any, strokewidth: any) => mxShape' is not assignable to parameter of type 'new (...args: any) => mxShape'. 
Type '(bounds: any, fill: any, stroke: any, strokewidth: any) => mxShape' provides no match for the signature 'new (...args: any): mxShape'.

據我了解, new (...args: any): mxShape對於給定的情況應該足夠了,但是 Typescript 說,它不適合它。 為什么?

這就是我的 MxHeaderShape 的構建方式:

     function MxHeaderFooterShape(bounds, fill, stroke, strokewidth) : mxShape{
        let val = mxShape.call(this);
        this.bounds = bounds;
        this.fill = fill;
        this.stroke = stroke;
        this.strokewidth = (strokewidth != null) ? strokewidth : 1;
        return val;
    }

您似乎想創建一個擴展MxHeaderFooterShapemxShape 假設您正在使用typed-mxgraph ,您可以使用這種方式

import mx from './mxgraph'; // mxGraphExportObject returned by the mxgraph factory function
import { mxRectangle } from 'mxgraph';


class CustomMxShape extends mx.mxShape {

  constructor(bounds: mxRectangle, fill: string, stroke: string, strokewidth?: number) {
    super(bounds, fill, stroke, strokewidth);
  }

}

您還可以查看此演示: https://github.com/typed-mxgraph/typed-mxgraph-example-bundled-with-webpack/blob/7f0bf757aedb12cec84d86b4c4e4cbcb0f7a8147/src/app/custom-shapes.ts

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM