Select to view content in your preferred language

Typescript event inference no longer working

428
2
Jump to solution
02-26-2026 03:42 AM
JonathanDawe_BAS
Frequent Contributor

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;

 

0 Kudos
1 Solution

Accepted Solutions
mpatiiuk
Esri Contributor

Hi,

The error you are seeing is likely caused by an outdated "lib" setting in a tsconfig.json file in your project.

In particular, the "lib" setting is likely set to a value older than 2021, which does not include the WeakMap type, causing EventedCallback type to silently fail back to `any`.

We recommend setting "lib" to a more recent value, like es2024. See recommended example. For more details, see system requirements.

View solution in original post

2 Replies
mpatiiuk
Esri Contributor

Hi,

The error you are seeing is likely caused by an outdated "lib" setting in a tsconfig.json file in your project.

In particular, the "lib" setting is likely set to a value older than 2021, which does not include the WeakMap type, causing EventedCallback type to silently fail back to `any`.

We recommend setting "lib" to a more recent value, like es2024. See recommended example. For more details, see system requirements.

JonathanDawe_BAS
Frequent Contributor

Thanks @mpatiiuk that is indeed the case I had it set to ES2020 😓, updating it makes sense based on as you said the system requirements of the api!

0 Kudos