sindresorhus / got

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

Unusable with typescript 4: typing of got is wrong. #1458

Closed Nokel81 closed 4 years ago

Nokel81 commented 4 years ago

Describe the bug

Actual behaviour

The type of res in the following is unknown:

const res = await got.post('https://httpbin.org/anything', {
        json: {
            hello: 'world'
        },
        responseType: 'json'
    });

Expected behaviour

The type to be Response

Checklist

Giotino commented 4 years ago

I just tested it with Node.JS v12.18.0, Typescript v4.0.2 and Got v11.6.2.

The type of res is Response<unknown> which is correct.

Nokel81 commented 4 years ago

Ah I see now what caused me to fail, I had a function that returned Options which doesn't help the typing very much....

Sorry for the noise.

Nokel81 commented 4 years ago

Though I do think that the type for the options of got.stream(...) should be exported.