From b2e070fa936060933de6115626eb2f75df4484b9 Mon Sep 17 00:00:00 2001 From: "Matt R. Wilson" Date: Mon, 22 Jan 2018 14:46:03 -0700 Subject: [PATCH] [@types/request-promise] Stop extending Promise. (#23087) Both `@types/request-promise` and `@types/request-promise-native` were extending their particular `Promise` implementations, however, the actual libs don't extend these objects. All they do is add logic to the `Request.prototype.init` function and "expose" a few defined methods from theit `Promise` implementations. This came up while looking into the issue on #23004. --- types/request-promise-native/index.d.ts | 5 ++++- .../request-promise-native-tests.ts | 1 + types/request-promise/index.d.ts | 11 +++++++++-- types/request-promise/request-promise-tests.ts | 2 ++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/types/request-promise-native/index.d.ts b/types/request-promise-native/index.d.ts index 29e0e0f72c..e4fc27a8c2 100644 --- a/types/request-promise-native/index.d.ts +++ b/types/request-promise-native/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for request-promise-native 1.0 // Project: https://github.com/request/request-promise-native // Definitions by: Gustavo Henke +// Matt R. Wilson // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -8,7 +9,9 @@ import request = require('request'); import http = require('http'); declare namespace requestPromise { - interface RequestPromise extends request.Request, Promise { + interface RequestPromise extends request.Request { + then: Promise["then"]; + catch: Promise["catch"]; promise(): Promise; } diff --git a/types/request-promise-native/request-promise-native-tests.ts b/types/request-promise-native/request-promise-native-tests.ts index 469b901143..b4c66bd2d8 100644 --- a/types/request-promise-native/request-promise-native-tests.ts +++ b/types/request-promise-native/request-promise-native-tests.ts @@ -25,6 +25,7 @@ rpn('http://google.com').then(() => { }); rpn('http://google.com').then(console.dir); rpn('http://google.com').catch(console.error); rpn('http://google.com').then(console.dir, console.error); +rpn('http://google.com').promise().then(console.dir); rpn({ uri: 'http://google.com', resolveWithFullResponse: true }).then((response) => { }); rpn({ uri: 'http://google.com', simple: false }).catch((reason) => { }); diff --git a/types/request-promise/index.d.ts b/types/request-promise/index.d.ts index 7094d478d6..8e811a415e 100644 --- a/types/request-promise/index.d.ts +++ b/types/request-promise/index.d.ts @@ -1,6 +1,9 @@ // Type definitions for request-promise 4.1 // Project: https://github.com/request/request-promise -// Definitions by: Christopher Glantschnig , Joe Skeen , Aya Morisawa +// Definitions by: Christopher Glantschnig +// Joe Skeen +// Aya Morisawa +// Matt R. Wilson // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -10,7 +13,11 @@ import errors = require('./errors'); import Promise = require('bluebird'); declare namespace requestPromise { - interface RequestPromise extends request.Request, Promise { + interface RequestPromise extends request.Request { + then: Promise["then"]; + catch: Promise["catch"]; + finally: Promise["finally"]; + cancel: Promise["cancel"]; promise(): Promise; } diff --git a/types/request-promise/request-promise-tests.ts b/types/request-promise/request-promise-tests.ts index e23a94dd2a..421e4ef766 100644 --- a/types/request-promise/request-promise-tests.ts +++ b/types/request-promise/request-promise-tests.ts @@ -23,6 +23,8 @@ rp('http://google.com').finally(() => {}); rp('http://google.com').then(console.dir); rp('http://google.com').catch(console.error); rp('http://google.com').then(console.dir, console.error); +rp('http://google.com').cancel(); +rp('http://google.com').promise().then(console.dir); // This works as well since additional methods are only used AFTER the FIRST call in the chain: