Error TS2740 in Typescript source for Angular application

1576
1
Jump to solution
09-08-2021 04:16 AM
PaoloF
by
New Contributor III

Hi everyone in the Community.

I'm developing an Angular application using Typescript and ES modules syntax, but I'm facing a problem when I try to define some ArcGIS objects taking source from sample API application on Esri website.

For example the following code fails:

import Point from '@arcgis/core/geometry/Point';

...

const point: Point = {
  //Create a point
  type: 'point',
  longitude: 12.600913,
  latitude: 42.55151,
};

according to following pages on API documentation:

https://developers.arcgis.com/javascript/latest/add-a-point-line-and-polygon/
https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Point.html

but just at editing time I got this error:

error TS2740: Type '{ type: "point"; longitude: number; latitude: number; }' is
missing the following properties from type 'Point': m, x, y, z, and 21 more.

Same behaviour occurs if I define in different ways the object.

May any of you explain what I'm making wrong and how to solve it?

Thanks in advance and best regards.

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Honored Contributor

Typescript doesn't allow for autocasting, which is what's being used in line 7. To create a point, you'll have to use something like

const point: Point = new Point({
  longitude: 12.600913,
  latitude: 42.55151,
  etc.
});

 

View solution in original post

1 Reply
KenBuja
MVP Honored Contributor

Typescript doesn't allow for autocasting, which is what's being used in line 7. To create a point, you'll have to use something like

const point: Point = new Point({
  longitude: 12.600913,
  latitude: 42.55151,
  etc.
});