AnsweredAssumed Answered

How to await MapView with TypeScript

Question asked by alanmervitz on Jun 20, 2017
Latest reply on Jun 20, 2017 by TSolow-esristaff

I'm using TypeScript and wondering if there's a better way to await a MapView than what I'm currently doing. The example in the documentation shows how to supply a callback for the then promise when using vanilla JavaScript:

var view = new MapView();
view.then(function(){
  // This code will execute once the promise is resolved
});

What I'd like to do is use the await keyword to avoid the nested function call. This is the only way I've been able get this to work:

let view = new MapView();
await view.then(() => {});
// This code will execute once the promise is resolved

Ideally I would be able to write something like this:

let view = new MapView();
await view;
// this code will execute after the promise is resolved

Although it doesn't compile with this error:

Type of 'await' operand must either be a valid promise or must not contain a callable 'then' member.

Thanks,

Alan

Outcomes