is optional by adding the identifier
export interface LineChartProps {
...
yAxesTicksMin?: number,
yAxesTicksMax?: number,
yAxesTicksCallback?: (value: number | string, index: number, values: number[] | string[]) => string | number | null | undefined
}
. Consequently TypeScript will compile this as yAxesTicksCallback
the latter which causes the error when you're typecasting it to the function type. There's a bunch of ways to resolve this and it's a bit hard to advise on the best one without further context–but the first thing I'd investigate is if it's possible to remove the
...
yAxes: [{
ticks: {
min: yAxesTicksMin as number,
max: yAxesTicksMax as number,
stepSize: 1,
callback: yAxesTicksCallback as (value: number | string, index: number, values: number[] | string[]) => string | number | null | undefined,
},
...
from the interface, this would allow you to remove the typecasting as well. I think this is nice because usually when I implement a typecast, I later find out that I was just being lazy and could structure my code in a better way. (使用Chart.js)TypeError: undefined is not a function
我得到了以下接口。callback
然后在ChartJS对象中 "填充 "我的图表组件,我得到了一个变量
来代替回调。
问题就在这里开始了 当我定义 "变量为类型 "时,它抛出了以下错误。 在原来的界面(ChartJs界面)中也有同样的类型。yAxesTicksCallback
谢谢,我得到的接口如下:export interface LineChartProps { ...?
() => ... | undefined
?
我得到了以下接口: export interface LineChartProps { ... yAxesTicksMin?: number, yAxesTicksMax?: number, yAxesTicksCallback?