How do I use RequestPromise in TypeScript?

request-promise encoding
request typescript
request-promise proxy
request-promise-native example
request-promise payload
typescript statuscodeerror

I have installed request-promise library and trying to use it in my TypeScript app but without much luck.

If I use it like this:

import {RequestPromise} from'request-promise';

        .then(function (htmlString) {
            // Process html...
        .catch(function (err) {
            // Crawling failed...

I see this on TS compile output:

error TS2304: Cannot find name 'RequestPromise'.

If I use it this way:

import * as rp from'request-promise';

    .then(function (htmlString) {
        // Process html...
    .catch(function (err) {
        // Crawling failed...

I see an error that says that there is no '.then()' method on object rp.

How do I properly use it with TypeScript?

You must import all (*) not just RequestPromise:

import * as request from "request-promise";

This answer elaborates on the differences between import/from and require.

patdaburu/request-promise-typescript-example: Wondering , Using async-await and npm-promise with TypeScript. Wondering how to use Async/Await with the request module in TypeScript? So was I. In this example, we'll use the request-promise module. It's a Javascript module, but fortunately we can make it visible to TypeScript by grabbing the @types/request-promise module also. Example #1. In this example we simply make an asynchronous call using async-await and request-promise to get our own IP address. You can view the code here. Test Links

request-promise has a package for typescript

  1. npm i --save-dev @types/request-promise
  2. import { get, put, post } from 'request-promise';
get(options).then(body => {


}).catch(e => reject);

@types/request-promise, TypeScript definitions for request-promise. Installation. npm install --save @​types/request-promise. Summary. This package contains type  A TypeScript promise takes inner function, and that inner function accepts resolve and rejects parameter. If we talk about Promise, so it works the same way we make promises to others. In a real-world scenario, when we make a promise to somebody that means the surety of doing something in the future.

I use request-promise in this way

import * as requestPromise from 'request-promise';

const options = {
    uri: _url,
    headers: {
        Authorization: 'Bearer ' + token

requestPromise.get(options, (error, response) => {
    if (error) {
        // Do error handling stuff
    } else {
        if (response.statusCode !== 200) {
             // Do error handling stuff
        } else {
             // Do success stuff here

request-promise, However, you can get back the support by using request-promise-any . When you migrated your transform function to v3 and had to add if (!(/^2/.test('' + response. Promises in TypeScript We begin by creating a simple promise like this: const one = new Promise<string> ((resolve, reject) => {}); In this Promise, I have used the promise constructor to take in string as the generic type for the Promise’s resolve value.

How do I use RequestPromise in TypeScript?, I see this on TS compile output: error TS2304: Cannot find name '​RequestPromise'. If I use it this way: import * as rp from'request-promise'; Technically, Request-Promise is just calling Request with passing a callback. Please compare your two implementations if they are identical and if they use the same Request version. If you can't spot anything what is the error you get in the Request-Promise version?

@types/request-promise: Docs, Tutorials, Reviews, types/request-promise documentation, tutorials, reviews, alternatives, versions, dependencies, community, and more. The repository for high quality TypeScript type definitions. npm i @types/request- Easy to Use. 0. What I want to do and notice how I’m using our fat arrow syntax for the function here I’m going to console log out something and we’re to use string interpellation So the use of tactics and a status and asset status equal to whatever the value of image status is. And right after the curly brackets, I’m going to do another backtick.

Asynchronous Programming in TypeScript, We will first use a Node module called request to interact with an http server. get request using request-promise-native function getRequestPromise(url: string,​  Second, Promise.TypeScript is itself written in TypeScript, making it easier (for me) to read. Third, the combination of the comments in the Promise.TypeScript file (Promise.ts) and the provided sample code are very helpful in getting started with Promises (you'll find the link to the sample code in the comments at the top of the Promise.ts file).

  • Have you tried import rp from 'request-promise'; and then using rp as you have above?
  • Now it compiles, but I see TypeError: Uncaught error: request_promise_1.default is not a function now when running the app and calling that code.
  • I tried import rp = require('request-promise') and it fixed the error. Thanks!
  • I didn't understand why this works until I read this answer. TL;DR - import * as creates a module object, which is not "callable" like a function.
  • Why don't you use it as a promise (with .then(...)) but as a callback?