Use async/await with TypeScript in NativeScript today

Async/await allows developers to write asynchronous code as if they were synchronous. Support for async/await in TypeScript is available when targeting ES6 but down compiling to ES5 is yet to be implemented. So long the story can be summarized in TypeScript -> ES6 -> Babel -> ES5. And this was the official story from the TypeScript team.

Recently commits on down-compiling TypeScript to ES5 were merged in the TypeScript master, making them available in typescript@next, this way the Babel step is avoided and TypeScript compiles directly to ES5.

If VSCode asks you to use the TypeScript installed in the workspace - go yes, currently if you don't, it will use an official TS version, and may complain about async being supported when targeting ES6.

Run

The NativeScript TypeScript plugin uses TypeScript compiler installed as dependency (similar to the way VSCode got it working) so it will automatically pick the latest version.

Now the down-compiled code will work in our ES5 environments. Keep in mind the iOS and Android runtimes use custom builds on JavaScriptCore and V8 so new ES features get adopted quickly, we may see TypeScript -> ES6 ready quite soon.

Enterprise

Stay connected with NativeScript

I agree to receive email communications from Progress Software or its Partners, containing information about Progress Software’s products. Consent may be withdrawn at any time.

We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.

Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.