You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There appears to be an issue in how RequestInit type is declared for DOM and Node 20.x that's blocking me from using oazapfts in server-side Node code.
in @types/node (v20.8.10), RequestInit type definition is imported from the undici-types package. In v5.26.5 of that package, RequestInit.signal is defined like this:
Which is not compatible with the Node @types version.
It appears that oazapfts is compiled against the DOM declaration of RequestInit. The return type of json, form and multipart functions is not specified in code. The generated declaration file has the DOM version of RequestInit that supports null as an option for signal. Meanwhile, fetchText, fetchJson and fetchBlob all take a FetchRequestOpts as their 2nd argument.
From lib/runtime/index.d.ts in the oazapfts package
Arguably, the right solution here would be to update undici-types to match the declaration in lib.dom.d.ts and wait for that update to eventually get pulled into @types/node. However, oazapfts can work around this in one of two ways:
Explicitly specifying the return type of json, form and multipart as FetchRequestOpts.
Modify the implementation of those functions so that signal is always typed as AbortSignal | undefined, which is compatible with both DOM and Node's declaration of RequestInit.
json({ body, headers, ...req}: JsonRequestOpts){return{
...req,
...(body!=null&&{body: JSON.stringify(body)}),// the following line to forces signal's type to AbortSignal | undefinedsignal: req.signal ? req.signal : undefined,headers: {
...headers,"Content-Type": ensureJsonContentType(String(headers?.["Content-Type"]),),},};},
I'm happy to open a PR to fix this. Please let me know which approach is preferable.
The text was updated successfully, but these errors were encountered:
Updates shop frontend to use
[oazapfts](https://github.com/oazapfts/oazapfts) and payment frontend to
use [OpenAPI Typescript
Codegen](https://github.com/ferdikoomen/openapi-typescript-codegen) for
generating client code.
I used two different code generators because I discovered a [bug in
oazapfts](oazapfts/oazapfts#508) that prevents
it's use in payment after I had already updated shop.
Note, I'm using utility types to give nice type names to the generated
types that have ugly names or are anonymous types. For example, in
payment client, I use the following to give a friendly name to the type
retuned by `getSessionInformation`
```ts
type PaymentSessionInformation = Awaited<ReturnType<typeof api.getSessionInformation>>
```
shop is even more interesting because oazapfts returns a response object
w/ the return value in the `data` field. So I created a custom utility
type to extract the data field's type and combined it with `Awaited` and
`ReturnType` to create friendly type names for use in the rest of the
code:
```ts
type DataFieldType<T> = T extends { data: infer U } ? U : never
type OazapftsReturn<T extends (...args: any) => any> = DataFieldType<Awaited<ReturnType<T>>>
export type Product = OazapftsReturn<typeof $api.getProduct>
```
There appears to be an issue in how
RequestInit
type is declared for DOM and Node 20.x that's blocking me from using oazapfts in server-side Node code.in
@types/node
(v20.8.10),RequestInit
type definition is imported from theundici-types
package. In v5.26.5 of that package,RequestInit.signal
is defined like this:In
lib.dom.d.ts
(TS 5.2.2),RequestInit.signal
is defined like this:Which is not compatible with the Node @types version.
It appears that oazapfts is compiled against the DOM declaration of
RequestInit
. The return type ofjson
,form
andmultipart
functions is not specified in code. The generated declaration file has the DOM version ofRequestInit
that supports null as an option forsignal
. Meanwhile,fetchText
,fetchJson
andfetchBlob
all take aFetchRequestOpts
as their 2nd argument.From
lib/runtime/index.d.ts
in the oazapfts packageArguably, the right solution here would be to update
undici-types
to match the declaration inlib.dom.d.ts
and wait for that update to eventually get pulled into@types/node
. However, oazapfts can work around this in one of two ways:json
,form
andmultipart
asFetchRequestOpts
.signal
is always typed asAbortSignal | undefined
, which is compatible with both DOM and Node's declaration ofRequestInit
.I'm happy to open a PR to fix this. Please let me know which approach is preferable.
The text was updated successfully, but these errors were encountered: