/async_await_typescript

:trident: ES7 async/await example using TypeScript & node v6 with Visual Studio Code 1.0

Primary LanguageJavaScript

async/await with TypeScript

This example demonstrates the use of async/await using TypeScript v1.9-dev, Node.js v6 and Visual Studio Code v1.0;

$ node lib/await.js
1
2
3
Error: throw error to showcase source map support.
    at /async_await_typescript/lib/await.ts:21:9
    at undefined.next (native)
    at fulfilled (/async_await_typescript/lib/await.js:4:58)

Manually compile using gulp. To run tsc directly, use tsc -p .

Install dependencies

Visual Studio Code Integration

  • File ▸ Auto Save Enable auto save.
  • Gulp tasks are auto detected and made available in the task list. On a Mac Shift + Command + P ▸ Run Task ▸ Press Enter then select Watch.
  • Watch automatically compiles TypeScript according to the gulpfile rules.

Directory Overview

.
├── .vscode
│   ├── launch.json
│   └── settings.json
├── lib
│   ├── await.js
│   └── await.js.map
├── node_modules
├── ts
│   └── await.ts
├── .gitignore
├── gulpfile.js
├── jsconfig.json
├── package.json
├── readme.md
├── tsconfig.json

Workflow

node --v8-options | grep "in progress"

Node lacks support for ES6 modules because v8 hasn't implemented them As a result module type commonjs is used in tsconfig.json.

  • typescript Transpiles ES 7 to ES 6
  • node.js Runs ES 6/5 hybrid

TypeScript offers granular targeting via the lib compiler option specified in tsconfig.

Debugging

Visual Studio Code supports debugging TypeScript with source map support.

Credits