feat(fetch): introduce `HttpMethod` type and update `RequestInit` method typing
This relates to...
This PR enhances the developer experience by adding proper TypeScript typing for HTTP methods and missing RequestInit properties to match the standard Fetch API specification. https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods
Added a new HttpMethod type to define valid HTTP methods and updated the method property in RequestInit to use this type. Updated tests to reflect these changes.
Rationale
Changes
Enhanced TypeScript Definitions
- Added
HttpMethodtype: Union of standard HTTP methods + extensible string type using(string & {})pattern - Updated
RequestInit.method: Now typed asHttpMethodinstead of genericstring
Test Coverage
- Added comprehensive TypeScript tests for all new properties and types
- Enhanced method testing to verify
HttpMethodtyping works correctly - Maintained backward compatibility - all existing code continues to work
Features
- HTTP Method Autocompletion: IntelliSense now suggests standard HTTP methods (GET, POST, PUT, DELETE, HEAD, OPTIONS, PATCH, TRACE, CONNECT)
- Extensible Method Typing: Custom HTTP methods still work via
(string & {})pattern - Improved Developer Experience: Better type safety and IDE support
Bug Fixes
Breaking Changes and Deprecations
None - This is a purely additive change that maintains full backward compatibility. All existing code will continue to work without modification.
Status
- [x] I have read and agreed to the Developer's Certificate of Origin
- [x] Tested
- [ ] Benchmarked (optional)
- [ ] Documented
- [ ] Review ready
- [ ] In review
- [ ] Merge ready
Breaking Changes and Deprecations None - This is a purely additive change that maintains full backward compatibility. All existing code will continue to work without modification.
Isn't this a breaking change? It won't be possible to merge of declarations of the following declare module 'undici' {interface RequestInit {method?: string;}} .
@tsctx You're right about the issue. I've found this is a fundamental TS limitation after testing:
-
method?: string→ Module augmentation works but no autocompletion -
method?: HttpMethod→ Autocompletion works but breaks module augmentation
But it works like this
import "undici"
import type { HttpMethod } from "undici";
declare module "undici" {
interface RequestInit {
method?: HttpMethod;
}
}