[@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.
This commit is contained in:
Matt R. Wilson
2018-01-22 14:46:03 -07:00
committed by Andy
parent 04a5483d77
commit b2e070fa93
4 changed files with 16 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
// Type definitions for request-promise-native 1.0
// Project: https://github.com/request/request-promise-native
// Definitions by: Gustavo Henke <https://github.com/gustavohenke>
// Matt R. Wilson <https://github.com/mastermatt>
// 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<any> {
interface RequestPromise extends request.Request {
then: Promise<any>["then"];
catch: Promise<any>["catch"];
promise(): Promise<any>;
}

View File

@@ -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) => { });

View File

@@ -1,6 +1,9 @@
// Type definitions for request-promise 4.1
// Project: https://github.com/request/request-promise
// Definitions by: Christopher Glantschnig <https://github.com/cglantschnig>, Joe Skeen <https://github.com/joeskeen>, Aya Morisawa <https://github.com/AyaMorisawa>
// Definitions by: Christopher Glantschnig <https://github.com/cglantschnig>
// Joe Skeen <https://github.com/joeskeen>
// Aya Morisawa <https://github.com/AyaMorisawa>
// Matt R. Wilson <https://github.com/mastermatt>
// 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<any> {
interface RequestPromise extends request.Request {
then: Promise<any>["then"];
catch: Promise<any>["catch"];
finally: Promise<any>["finally"];
cancel: Promise<any>["cancel"];
promise(): Promise<any>;
}

View File

@@ -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: