signal
is not nullable in types of RequestInit
#2448
Labels
bug
Something isn't working
fetch
good first issue
Good for newcomers
Types
Changes related to the TypeScript definitions
Bug Description
According to the Fetch standard, the
signal
property inRequestInit
might be nullable. However, currently,@types/node
that use typings from this package do not allow setting that property tonull
and cause TypeScript errors.Reproducible By
Create a new package with the following dependencies:
@types/node
andtypescript
.Create a
tsconfig.json
file with the following content:Create a
main.mts
file with the following content:Compile the project using
tsc
.Expected Behavior
There should be no error and TypeScript should compile
main.mts
.Logs & Screenshots
This produces the following error:
Environment
Node v18.18.2,
@types/node
v20.9.3 (withundici-types
v5.26.5)Additional context
This works fine when adding
"dom"
to thelib
option intsconfig.json
(or when using@types/web
) as the built-in DOM types allow settingsignal
tonull
:This error makes it impossible to write concise app-specific
fetch
wrappers:undefined
can be used instead ofnull
as the right-hand side of the nullish coalescing operator in the preceding snippet, but only when theexactOptionalPropertyTypes
TypeScript compiler option is disabled. When combined with this flag, I'm forced to create fetch options in a verbose way:The text was updated successfully, but these errors were encountered: