hapijs / wreck

HTTP Client Utilities
Other
383 stars 103 forks source link

How do I reference the return type of a Wreck request in typescript #303

Open cybercode opened 1 year ago

cybercode commented 1 year ago

Support plan

Context

How can we help?

I am trying to use Wreck in a typescript hapi service. I am unable figure out how to get the type definition for the Wreck.Response.

examples, none of the following work

async function fetch() : Promise<Wreck.Response> {}

causes the error "Cannot find namespace 'Wreck'"

and

import Wreck {Response} from '@hapi/wreck';

"Module '"@hapi/wreck"' has no exported member 'Response'."

Marsup commented 1 year ago

I don't think it's exposed right now, is inference a problem?

Marsup commented 1 year ago

If you absolutely need it, you can get it pretty easily: https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAdSgUwMYGs4DMoRHAcgAEALAQzGAHoB3FDAgbgChmYBPMZOAcWRgBKyAM6QAdsOQAeACpwAvHACuY9GIg0xAPgVwhMJVDEzO0jlwhZE9dADoA5v1latLZmWHsxqbCtQxgCDFsflQSZwAKAEoALjgABVwQYEkpPkERcVSZFzgAb2Y4OBQDI2s0O0cYCIJbOoIolgBfIA

But it shouldn't be very hard to expose either.