-
-
Notifications
You must be signed in to change notification settings - Fork 366
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
Make types compatible with both DOM and Node.js #543
Conversation
NormalizedOptions
@@ -175,7 +175,7 @@ export class Ky { | |||
this._options.duplex = 'half'; | |||
} | |||
|
|||
this.request = new globalThis.Request(this._input as RequestInfo, this._options as RequestInit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't appear to be needed?
@@ -177,7 +178,7 @@ export type KyOptions = { | |||
const json = await ky('https://example.com', {fetch}).json(); | |||
``` | |||
*/ | |||
fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is breaking, but actually both @types/node
and lib.dom.d.ts
define it this way.
method: NonNullable<RequestInit['method']>; | ||
credentials: NonNullable<RequestInit['credentials']>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exactOptionalPropertyTypes: true
fails on this, as optional properties get resolved as Foo | undefined
, and that isn't compatible with RequestInit
.
I'm unable to publish this until #544 is figured out. |
That's alright, thanks for taking a look! |
sindresorhus#559 undid the fix in sindresorhus#543.
sindresorhus#559 undid the fix in sindresorhus#543.
sindresorhus#559 undid the fix in sindresorhus#543. Added `exactOptionalPropertyTypes` to `compilerOptions` to prevent this from happening again, seems pretty low-impact. It should be okay to pass `undefined` to `credentials` and other options, but this is an upstream problem (see `RequestInit` in `undici-types/fetch.d.ts`). The build was failing on TS 5.4 because there's a `priority` in `RequestInit` now.
Otherwise TypeScript fails with
skipLibCheck: false
,exactOptionalPropertyTypes: true
and noDOM
:Would add a test, but it doesn't seem like there are any type tests. How do you want to go about this?