TS2345错误,但参数应该没问题?
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;
}
您似乎想创建一个扩展 mxShape
的 MxHeaderFooterShape
class。
假设你正在使用typed-mxgraph,你可以使用这种方式做
import mx from './mxgraph'; // mxGraphExportObject returned by the mxgraph factory function
import type { mxRectangle } from 'mxgraph';
class CustomMxShape extends mx.mxShape {
constructor(bounds: mxRectangle, fill: string, stroke: string, strokewidth?: number) {
super(bounds, fill, stroke, strokewidth);
}
}
所以我有这个错误:
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;
}
您似乎想创建一个扩展 mxShape
的 MxHeaderFooterShape
class。
假设你正在使用typed-mxgraph,你可以使用这种方式做
import mx from './mxgraph'; // mxGraphExportObject returned by the mxgraph factory function
import type { mxRectangle } from 'mxgraph';
class CustomMxShape extends mx.mxShape {
constructor(bounds: mxRectangle, fill: string, stroke: string, strokewidth?: number) {
super(bounds, fill, stroke, strokewidth);
}
}