I'm beginning the process of reworking some JS apps to use the new components framework and am running into issues with TypeScript typings. The simple example shown in the docs for the Scene component shows this bit of code:
const arcgisScene = document.querySelector("arcgis-scene");
arcgisScene.addEventListener("arcgisViewReadyChange", () => {
const layer = new GraphicsLayer({ title: "My layer"});
arcgisScene.map.add(layer);
});If I try to copy this exactly using TypeScript, my IDE (IntelliJ) can't find the arcgisScene.map property. I've installed the modules with npm, and my code looks like this:
import "@arcgis/map-components/components/arcgis-scene";
function loadMap(): void {
const arcgisScene = document.querySelector("arcgis-scene");
arcgisScene!.addEventListener("arcgisViewReadyChange", () => {
const layer = new GraphicsLayer({ title: "My layer"});
arcgisScene!.map.add(layer);
});
}In the IDE, I can see that TS is inferring that arcgisScene is of the type HTMLArcgisSceneElement | null, but it can't find the map property.
However, if I explicitly define the type of arcgisScene as HTMLArcgisSceneElement | null, the IDE can find the map property when I hover over it, but it still gives me the "Property map does not exist on type HTMLArcgisSceneElement" error.
The app does seem to work once everything is compiled to JavaScript and bundled, but I'd like to fix the IDE errors if possible