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
The cast looks like it did the trick as far as getting rid of the linter errors. I do appreciate that. Would casting possibly fix the issues @micsova was asking about you think? I'm newer to typescript, coming from a C# background mainly. Not sure of the prevalence of type casting in cases like these.
Type casting is not required often.
The original comment had a type error accessing the arcgisScene.map property. I see that property in our documentation, so I am not sure why the issue is present. A GitHub repository link or other way to see the fuller project setup would be helpful to diagnose the issue.