From 830e8ebd9ef137d039d5c7ede24a421f08595f83 Mon Sep 17 00:00:00 2001 From: Sean Kelley Date: Wed, 3 Feb 2016 12:41:33 -0800 Subject: [PATCH] Rename the type variable for es6-promise from R to T to match lib.d.ts. This fixes an issue where two definitions for Promise that /should/ agree (i.e., be assignable to one another) aren't, and instead the immensely confusing error message: error TS2314: Generic type 'Promise' requires 2 type argument(s). Even though all the present definitions are paramaterized with a single type variable, Typescript appears to assume that the two different names are referring to two different types and therefore you must supply both. Here I changed it to T from R so that it matches lib.d.ts. For reference, this error occured for me specifically when I had both es6-promise and bluebird typings present. bluebird uses T already. --- es6-promise/es6-promise.d.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/es6-promise/es6-promise.d.ts b/es6-promise/es6-promise.d.ts index a8f8d7845..c0a77edd8 100644 --- a/es6-promise/es6-promise.d.ts +++ b/es6-promise/es6-promise.d.ts @@ -3,13 +3,13 @@ // Definitions by: François de Campredon , vvakame // Definitions: https://github.com/borisyankov/DefinitelyTyped -interface Thenable { - then(onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => U | Thenable): Thenable; - then(onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => void): Thenable; +interface Thenable { + then(onFulfilled?: (value: T) => U | Thenable, onRejected?: (error: any) => U | Thenable): Thenable; + then(onFulfilled?: (value: T) => U | Thenable, onRejected?: (error: any) => void): Thenable; catch(onRejected?: (error: any) => U | Thenable): Thenable; } -declare class Promise implements Thenable { +declare class Promise implements Thenable { /** * If you call resolve in the body of the callback passed to the constructor, * your promise is fulfilled with result object passed to resolve. @@ -17,7 +17,7 @@ declare class Promise implements Thenable { * For consistency and debugging (eg stack traces), obj should be an instanceof Error. * Any errors thrown in the constructor callback will be implicitly passed to reject(). */ - constructor(callback: (resolve : (value?: R | Thenable) => void, reject: (error?: any) => void) => void); + constructor(callback: (resolve : (value?: T | Thenable) => void, reject: (error?: any) => void) => void); /** * onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects. @@ -29,8 +29,8 @@ declare class Promise implements Thenable { * @param onFulfilled called when/if "promise" resolves * @param onRejected called when/if "promise" rejects */ - then(onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => U | Thenable): Promise; - then(onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => void): Promise; + then(onFulfilled?: (value: T) => U | Thenable, onRejected?: (error: any) => U | Thenable): Promise; + then(onFulfilled?: (value: T) => U | Thenable, onRejected?: (error: any) => void): Promise; /** * Sugar for promise.then(undefined, onRejected) @@ -45,7 +45,7 @@ declare module Promise { * Make a new promise from the thenable. * A thenable is promise-like in as far as it has a "then" method. */ - function resolve(value?: R | Thenable): Promise; + function resolve(value?: T | Thenable): Promise; /** * Make a promise that rejects to obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error @@ -57,12 +57,12 @@ declare module Promise { * the array passed to all can be a mixture of promise-like objects and other objects. * The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value. */ - function all(promises: (R | Thenable)[]): Promise; + function all(promises: (T | Thenable)[]): Promise; /** * Make a Promise that fulfills when any item fulfills, and rejects if any item rejects. */ - function race(promises: (R | Thenable)[]): Promise; + function race(promises: (T | Thenable)[]): Promise; } declare module 'es6-promise' {