Chartjs-How can we type a variable which is a method in TypeScript ? (Using Chart.js)

0👍

In you type definition you declare that yAxesTicksCallback is optional by adding the identifier ?. Consequently TypeScript will compile this as () => ... | undefined 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 ? 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.

Leave a comment