dcsan dcsan - 1 year ago 211
TypeScript Question

how to use es6-promises with typescript?

I read this SO question but having trouble getting promises to work with typescript. Hopefully we can make a clear guide.
This is for a server/node project. I'm actually using latest iojs, but targeting ES5 as output.

$ tsd query es6-promise --action install --save
$ npm install --save es6-promise

// typescript code:

/// <reference path="../../typings/es6-promise/es6-promise.d.ts"/>

var Promise = require("es6-promise").Promise;

function test():Promise {
var p:Promise = new Promise();
return p;

this is giving the error:

Cannot find name 'Promise'.

// alternatively:

var p = new Promise<string>((resolve, reject) => {
resolve('a string');

//error=> Untyped function calls may not accept type arguments.

What is the recommended way to return a Promise from your own node server side code?


Answer Source


import {Promise} from 'es6-promise';
const p: Promise<string> = new Promise (
   (resolve: (str: string)=>void, reject: (str: string)=>void) => {
      const a: string = "hello from Promise";
p.then((st) => {


    "compilerOptions": {
        "target": "es3",
        "module": "commonjs",
        "declaration": false,
        "noImplicitAny": false,
        "noLib": false
    "filesGlob": [
    "files": [


npm install es6-promise
tsd install es6-promise
node main.js
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download