sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

TS issue with got.stream #1682

Closed sinedied closed 3 years ago

sinedied commented 3 years ago

Describe the bug

Actual behavior

When copying the stream code example from the README in a TypeScript project with strict mode enable, I get this error:

error TS2339: Property 'stream' does not exist on type 'typeof import("/Users/sinedied/projects/nubesgen-vscode/node_modules/got/dist/source/index")'.

103       got.stream('https://sindresorhus.com'),

...

Expected behavior

No errors :)

...

Code to reproduce

Set up a TypeScript project, enable strict mode and copy the code example from readme:

import stream = require('stream');
import util = require('util').promisify;
import fs = require('fs');
import got = require('got');

const pipeline = util.promisify(stream.pipeline);

(async () => {
    await pipeline(
        got.stream('https://sindresorhus.com'),
        fs.createWriteStream('index.html')
    );
})();

Checklist

szmarczak commented 3 years ago

Can you create a repository? I'm not able to reproduce this.

szmarczak commented 3 years ago

Ah, I think you should use import got from 'got' instead.

szmarczak commented 3 years ago
import stream = require('stream');
import util = require('util');
import fs = require('fs');
import got from 'got';

const pipeline = util.promisify(stream.pipeline);

(async () => {
    await pipeline(
        got.stream('https://sindresorhus.com'),
        fs.createWriteStream('index.html')
    );
})();
sinedied commented 3 years ago

Thanks, works fine this way! Most Node.js don't support native TS imports, so I didn't thought of using that. Great job on the lib BTW! 👍