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';
RequestPromise('http://www.google.com')
        .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';
rp('http://www.google.com')
    .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?
Request-Promise adds a Bluebird-powered . then(...) method to Request call objects. By default, http response codes other than 2xx will cause the promise to be rejected.
This package is also deprecated because it depends on request . Fyi, here is the reasoning of request 's deprecation and a list of alternative libraries.
I'd strongly suggest using node-fetch. It is based on the fetch API in modern browsers.
You must import all (*) not just RequestPromise:
import * as request from "request-promise";
request.get(...);
This answer elaborates on the differences between import/from and require.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With