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 .
node -v
Ensure node is v6 or laternpm install .
Install deps defined in package.jsonFile ▸ Auto Save
Enable auto save.Shift + Command + P ▸ Run Task ▸ Press Enter
then select Watch..
├── .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
.vscode/settings.json
- Settings for Visual Studio Code.
Code ▸ Preferences ▸ Workspace Settings
to change..vscode/launch.json
- Launch Configuration that enables debugging in Visual Studio code.lib/await.js
- Output from TypeScript. lib
is a mix between ES6 and ES5.
This code runs on node v6 or better. lib/await.js.map
- Source maps allows tracing failures back to line numbers in the original typescript files.node_modules
- The dependencies defined in package.json
ts/await.ts
- TypeScript source files which are automatically transpiled on save by typescript..gitignore
- Standard git ignore file.gulpfile.js
- Gulp build system used to setup source maps, babel, and typescript.jsconfig.json
- Visual Studio Code config file
that defines the version of JavaScript used by the editor.package.json
- Standard npm package config that defines dependencies
and other metadata useful when publishing to npm.readme.md
- The document you're currently reading.tsconfig.json
- The typescript compiler options.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 offers granular targeting via the lib compiler option specified in tsconfig.
Visual Studio Code supports debugging TypeScript with source map support.