sindresorhus / ky

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

Make types compatible with both DOM and Node.js #543

Closed alecmev closed 8 months ago

alecmev commented 8 months ago

Otherwise TypeScript fails with skipLibCheck: false, exactOptionalPropertyTypes: true and no DOM:

Error: node_modules/ky/distribution/types/options.d.ts(226,18): error TS2430: Interface 'NormalizedOptions' incorrectly extends interface 'RequestInit'.
  Types of property 'credentials' are incompatible.
    Type 'RequestCredentials | undefined' is not assignable to type 'RequestCredentials'.
      Type 'undefined' is not assignable to type 'RequestCredentials'.
Error: node_modules/ky/distribution/types/options.d.ts(16,29): error TS2552: Cannot find name 'HeadersInit'. Did you mean 'KyHeadersInit'?
Error: node_modules/ky/distribution/types/options.d.ts(160,21): error TS2552: Cannot find name 'RequestInfo'. Did you mean 'RequestInit'?
Error: node_modules/ky/distribution/types/options.d.ts(226,18): error TS2430: Interface 'NormalizedOptions' incorrectly extends interface 'RequestInit'.
  Types of property 'method' are incompatible.
    Type 'string | undefined' is not assignable to type 'string'.
      Type 'undefined' is not assignable to type 'string'.

Would add a test, but it doesn't seem like there are any type tests. How do you want to go about this?

sindresorhus commented 8 months ago

I'm unable to publish this until https://github.com/sindresorhus/ky/issues/544 is figured out.

alecmev commented 8 months ago

That's alright, thanks for taking a look!