ArcGIS JS API & TypeScript & Visual Studio 2015

1095
4
Jump to solution
07-31-2017 12:13 PM
KarenLai
New Contributor

Hello, I'm using Visual Studio 2015 to try to create a widget for a web application and I'm having trouble getting started.  I'm following the tutorial on the ArcGIS API for JavaScript website: TypeScript - Setting up your development environment | ArcGIS API for JavaScript 4.4 , but I get red squiggles under all the properties, causing the application to not compile.  I think I installed the ArcGIS Typing correctly via npm.  An image is attached.  Any assistance would be greatly appreciated.  Thank you.

0 Kudos
1 Solution

Accepted Solutions
ThomasSolow
Occasional Contributor III

I'm not completely sure that this is the issue, but I think this may have to do with how the JS API typings work with "autocasting."   The signature for the basemap property is not string, it looks like:

interface BasemapProperties extends LoadableProperties {
  baseLayers?: Collection;
  id?: string;
  loaded?: boolean;
  portalItem?: PortalItemProperties;
  referenceLayers?: Collection;
  thumbnailUrl?: string;
  title?: string;
}

This means that although a string is valid for a basemap in javascript, it's not valid in typescript.  This issue discusses some workarounds: Typings for basemap not matching actual javascript · Issue #77 · Esri/jsapi-resources · GitHub 

You could try passing in { id: "streets" } to the basemap property.  It may accept that.  You could also try one of the workarounds in that github issue.

View solution in original post

0 Kudos
4 Replies
ThomasSolow
Occasional Contributor III

What is the error?  I'm not familiar with visual studio, but can you mouse over the underlined code to display the error?

0 Kudos
KarenLai
New Contributor

Thanks for taking a look, Thomas.  The attached image shows the error list. 

0 Kudos
ThomasSolow
Occasional Contributor III

I'm not completely sure that this is the issue, but I think this may have to do with how the JS API typings work with "autocasting."   The signature for the basemap property is not string, it looks like:

interface BasemapProperties extends LoadableProperties {
  baseLayers?: Collection;
  id?: string;
  loaded?: boolean;
  portalItem?: PortalItemProperties;
  referenceLayers?: Collection;
  thumbnailUrl?: string;
  title?: string;
}

This means that although a string is valid for a basemap in javascript, it's not valid in typescript.  This issue discusses some workarounds: Typings for basemap not matching actual javascript · Issue #77 · Esri/jsapi-resources · GitHub 

You could try passing in { id: "streets" } to the basemap property.  It may accept that.  You could also try one of the workarounds in that github issue.

0 Kudos
KarenLai
New Contributor

Thank you, Thomas!  The squiggles are all gone and the application compiled successfully.  This is a good start.  Thank you for your time!

0 Kudos