sindresorhus / ky

🌳 Tiny & elegant JavaScript HTTP client based on the Fetch API
MIT License
11.91k stars 342 forks source link

Export type KyInstance #529

Closed adematte closed 10 months ago

adematte commented 10 months ago

Thanks for this great lib 🙏

This is a small PR to export KyInstance to improve typescript support.

This is especially useful when using ky.create(...) to init a ky instance with new defaults in a class constructor. Without KyInstance type being exported it's impossible to type a class property holding the ky instance.

class Foo {
    #kyClient:KyInstance // can't be typed without exporting KyInstance

    constructor() {
        this.#kyClient = ky.create({
            headers: { 'PRIVATE-TOKEN': 'XXXXXXX' }
        })
    }
 // etc...
}
sindresorhus commented 10 months ago

Duplicate of https://github.com/sindresorhus/ky/pull/383

adematte commented 10 months ago

Duplicate of #383

makes perfect sense 👌