Configuring TypeScript to Work with Promises
This guide walks through how to configure your system to work with TypeScript promises. Specifically we update the compiler options in the tsconfig file to work with the ES6 runtime.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

In this guide and I'm going to talk about how we can upgrade our systems to be able to work with promises. Right out of the box typescript in typescript 2.0 does not come with promises unless you give a specific target. So the target by default if you're using typescript and you don't change your compiler options is going to be ES 5. However, ES 6 is an updated version of javascript and that allows for some more advanced functionality such as being able to include promises in different modules and classes like that. So before we get into how we can work with promises first we have to upgrade our system.

First thing that you should do is grab this line of code right here. sudo typings install dt~es6-promise dt~es6-collections --global --save This is if you're on a Mac and I will go through a separate guide if you're on a Windows machine and so take this code it's in the source code so if you go to show notes of this show then you can go access the code and grab the TS config file and you'll see this line right here and come to the terminal and simply paste it in and hit return. If you're running in sudo which I recommend it will ask for your password. Hit return and then it will go and install this for you. You need this you need the ES6 promise and ES6 collections. Now if this gives an air or anything like that then I recommend that you simply copy and paste the air paste it into Google because I did run into some older versions of this installation code that didn't work and it's really based on how Javascript is constantly evolving and there are a number of different upgrades and dependencies so if by the time you're watching this if that code doesn't work then that you can do exactly what I did which is Google theirs and I promise you will find there have probably been thousands of people who've done the exact same thing and you can get that code in there and get the typings installed.

So now with that in place you need to add two items to the compiler options here in TS config. The first is going to be changing the module. So change the module and add "amd" and you're going to do that inside of the curly brackets in compiler options and then also you want to update the target. And this code right here this is a comment so don't let that confuse you I just did it so you have access to it in the show notes. So the next thing is to change the target. So what this is essentially saying is that our compiler is now going to have a target of ES6 which is the latest version of Javascript. So this is what you need in order to run the code. So put those two things in and you'll be good to go with being able to work with promises which we'll get into in the next guide.

large

If you run into an error when you install the es6 module, make sure that you have TypeScript typings installed. You can run this command to install them:

sudo npm install typings --global

Resources