With the new version of the ArcGIS JS API I have run the typescript codemod and am now running through addressing any new typescript errors.
With the latest changes I'm finding that in many cases contextual type inference has been broken by the change. For example calling the `.on()` function on a mapview is giving me noImplicitAny errors when trying to handle the event.
import MapView from '@arcgis/core/views/MapView';
const view = new MapView();
view.on('pointer-move', (e) => {
// e is inferred as any, noImplicitAny error
console.log(e.x, e.y);
});
The issue is specifically being caused by the EventedMixin abstract class in the Evented.d.ts. If I change the on method type to use an overload it resolves most of the type errors I am now seeing in my codebase.
// rewrite with overload instead of EventedCallback.
on<Type extends EventNames<this>>(
type: Type,
listener: (event: this["@eventTypes"][Type]) => void
): ResourceHandle;
on<Type extends EventNames<this>>(
type: Type,
listener: WeakRef<(event: this["@eventTypes"][Type]) => void>
): ResourceHandle;