Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export KyInstance #383

Closed
wants to merge 1 commit into from
Closed

Export KyInstance #383

wants to merge 1 commit into from

Conversation

piitaya
Copy link
Contributor

@piitaya piitaya commented Oct 12, 2021

To avoid using typeof ky, we can use the KyInstance type.

@sindresorhus
Copy link
Owner

How is this better than just doing typeof ky which is shorter and doesn't require another import?

@piitaya
Copy link
Contributor Author

piitaya commented Oct 12, 2021

Some people (like me 😅) like to use build-in library types instead of inferring them but no problem if you don't think it's necessary 🙂

@sindresorhus
Copy link
Owner

I think it's better to limit the exported types to a minimum. A lot of random types can overwhelm the user. Since the user can already use typeof, I'm going to pass on this.

@ZachHaber
Copy link

I'd like you to reconsider exporting the KyInstance type. Typescript complains about the lack of KyInstance export when using "composite":true in the tsconfig:

src/index.ts:3:14 - error TS2742: The inferred type of 'api' cannot be named without a reference 
to './node_modules/ky/distribution/types/ky.js'. This is likely not portable. A type annotation 
is necessary.

3 export const api = ky.extend({});

It's possible to work around this by using export const api: typeof ky = ky.extend({}). Unfortunately, that fix is very much so non-intuitive when you are first encountering this error, and typescript itself doesn't make it easy to figure out the root cause of the error as the incremental builds appear to hide errors.

@sindresorhus
Copy link
Owner

That sounds more like a TypeScript bug if it only happens with "composite":true. Can you confirm that if you add this line to the ky package in your node_modules, it starts working for you?

@ZachHaber
Copy link

Yes, it starts working when I add the export:
image
image

That sounds more like a TypeScript bug if it only happens with "composite":true.

Honestly, I started looking into seeing if it was a bug in VSCode at first because I wasn't seeing the error in the console. While I was trying to set up a reproducible test case, I found out typescript itself was also showing the error. Eventually I figured out that tsconfig.tsbuildinfo swallows the error and doesn't display it again until something significant changes, or you delete the file.

I started looking into if it's an issue with TS, and I was reading the documentation on composite which states

All implementation files must be matched by an include pattern or listed in the files array. If this constraint is violated, tsc will inform you which files weren’t specified.

That lead me to here finding this PR though one of the weirdly similar duplicates of this one. At that point, I tried changing the index.d.ts file and realized that, yup, the error disappears the moment I add in the export.

The real bug in typescript is probably that the incremental builds don't display the error when re-running 🤦‍♂️

@sindresorhus
Copy link
Owner

https://github.com/sindresorhus/ky/releases/tag/v1.1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants