undici
undici copied to clipboard
fix: throws on unsupported option `path`
Refs: #1011
undici.request
accepts path
option but the type definition omits path
.
POC: https://github.com/is2ei/POC-nodejs-undici-1011
code: https://github.com/nodejs/undici/blob/d7eac3e4e57c387bfd954da7a28e84138c243d4c/index.js#L63-L75
@ronag Thanks for your comment. I basically try to solve 2 problems related to #1011.
- wrong type definition
- document for
undici.request
lacks some information.
When using TypeScript, you can not pass the path
option to undici.request
because the type definition omits the path
option. But when using JavaScript, you can pass the path
option to undici.request
and it works. So I fixed the type definition.
https://github.com/nodejs/undici/blob/d7eac3e4e57c387bfd954da7a28e84138c243d4c/index.js#L63-L68
Also, I found method
option is documented even though DispatchOptions
already has it. I guess the difference is method
is mandatory in DispatchOptions
but optional in undici.request
option. path
option has the same situation so I documented it.
https://github.com/nodejs/undici/blob/d7eac3e4e57c387bfd954da7a28e84138c243d4c/types/api.d.ts#L13-L17
When using TypeScript, you can not pass the path option to undici.request because the type definition omits the path option. But when using JavaScript, you can pass the path option to undici.request and it works. So I fixed the type definition.
I think the typescript version is correct and reflects intended/recommended usage.
Whether or not the javascript version should allow it is up for discussion. Maybe we should throw?
@ronag
Maybe we should throw?
Ok. I'll try.
Codecov Report
Merging #1282 (46451d9) into main (d7eac3e) will decrease coverage by
0.00%
. The diff coverage is100.00%
.
@@ Coverage Diff @@
## main #1282 +/- ##
==========================================
- Coverage 94.11% 94.11% -0.01%
==========================================
Files 44 44
Lines 4098 4096 -2
==========================================
- Hits 3857 3855 -2
Misses 241 241
Impacted Files | Coverage Δ | |
---|---|---|
index.js | 100.00% <100.00%> (ø) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update d7eac3e...46451d9. Read the comment docs.
@ronag I changed the code. Could you review it? I basically agree with your opinion, but I'd be worried if it would be a breaking change.