Typescript error TS2349 on view.goTo

957
5
Jump to solution
12-18-2017 02:41 PM
mingleidi
New Contributor II

When using MapView.goTo, it always gives Typescript error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((target: Geometry | Graphic | Graphic[] | Viewpoint | number[] | Geometry[] | MapViewGoToTarget,...' has no compatible call signatures.

The goto function working fine, just this tslint error breaks the build.

Does anyone have similar issues? below is my code:

if(matchedGraphic != null) {
let point = matchedGraphic.geometry as Point;
this.view.goTo({
center: [point.longitude, point.latitude],
zoom: 8
}, {
speedFactor: 6,
easing: "linear"
});

this.view.popup.open({
features: [matchedGraphic], // array of graphics
featureMenuOpen: true, // selected features initially display in a list
location: matchedGraphic.geometry
});
}

The typing file is:

goTo(target: number[] | Geometry | Geometry[] | Graphic | Graphic[] | Viewpoint | MapViewGoToTarget, options?: MapViewGoToOptions): IPromise<ViewAnimation>;

Just don't understand why tslint give this error, can someone shed some lights?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor

It could be a version thing. I am using Visual Studio Code and the version I'm using has TypeScript 2.6.1. and TSLint from here: GitHub - Microsoft/vscode-tslint: A tslint integration for vscode 

I've attached my test app. 

View solution in original post

0 Kudos
5 Replies
mingleidi
New Contributor II

After spent some time on google, seems it's because view.goto() uses union types which typescript doesn't like, one solution is to change source code to use method overload, which is not an option for me. Are there any other ways to resolve it?  

0 Kudos
KellyHutchins
Esri Frequent Contributor

I just ran a quick test using the latest version of the API (4.6) and the typings from here and when I didn't get any errors when transpiling. Here's the code I used. 

import Map = require("esri/Map");
import MapView = require("esri/views/MapView");
import Basemap = require("esri/Basemap");
const map = new Map({
basemap: Basemap.fromId("streets")
});
const view = new MapView({
map: map,
container: "viewDiv",
center: [-118.244, 34.052] as any,
zoom: 12
});

view.when(() => {
view.goTo({
center: [32.71, -117.16],
zoom: 8
})
});
 
0 Kudos
mingleidi
New Contributor II

Thanks Kelly, I downloaded the new type file and still get same error, could it because npm packages I used are different? here're what I used:

"typescript": "^2.6.2",
"ts-loader": "^3.2.0",
"tslint": "^5.8.0",

Could you upload your sample project?

Thanks!

0 Kudos
KellyHutchins
Esri Frequent Contributor

It could be a version thing. I am using Visual Studio Code and the version I'm using has TypeScript 2.6.1. and TSLint from here: GitHub - Microsoft/vscode-tslint: A tslint integration for vscode 

I've attached my test app. 

View solution in original post

0 Kudos
mingleidi
New Contributor II

Thanks Kelly, after compared your project with mine, I found the cause is that my view is declared as union type:

 

view: MapView | SceneView;

even if these two views has same goTo functions, typescript still doesn't like it, after manually cast my view to specific type, the error is gone, the error message is kind of misleading.

Thanks again for your help. much appreciated!

0 Kudos