Summary
The generated TypeScript types for the Request constructor don't allow passing a Request object as the second parameter, even though this is valid per the Fetch API specification and works correctly at runtime.
Current Behavior
const original = new Request('https://example.com/old', { method: 'POST', body: 'data' });
const cloned = original.clone();
// ❌ TypeScript error TS2345:
// Argument of type 'Request' is not assignable to parameter of type 'RequestInit'
const newRequest = new Request('https://example.com/new', cloned);
Error:
error TS2345: Argument of type 'Request<CfHostMetadata, Cf>' is not assignable to parameter of type 'RequestInit<CfProperties<unknown>>'.
Types of property 'cf' are incompatible.
Type 'Cf | undefined' is not assignable to type 'CfProperties<unknown> | undefined'.
Expected Behavior
The code should compile without error, as it does at runtime. Per the Fetch API spec, the Request constructor accepts either RequestInit or another Request as the second parameter.
Spec Reference
From Fetch Standard § 5.4:
The new Request(input, init) constructor steps are:
- Let request be null.
- ...
- If input is a string, then: ...
- Otherwise: Set request to input's request.
- ...
- If init is given, then: ...
The spec shows that init can be used alongside an existing Request to override specific properties while copying the rest.
Use Case
This pattern is common when you need to clone a request but change its URL:
// Rewrite URL while preserving method, headers, body, etc.
const rewrittenRequest = new Request(newUrl, originalRequest.clone());
Current Workaround
const rewrittenRequest = new Request(newUrl, originalRequest.clone() as RequestInit);
Suggested Fix
Update the Request constructor type signature from:
new <CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>>(
input: RequestInfo<CfProperties> | URL,
init?: RequestInit<Cf>
): Request<CfHostMetadata, Cf>;
To:
new <CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>>(
input: RequestInfo<CfProperties> | URL,
init?: RequestInit<Cf> | Request
): Request<CfHostMetadata, Cf>;
Environment
- Types generated via
wrangler types (wrangler 4.44.0+)
- workerd runtime types from
worker-configuration.d.ts
Summary
The generated TypeScript types for the
Requestconstructor don't allow passing aRequestobject as the second parameter, even though this is valid per the Fetch API specification and works correctly at runtime.Current Behavior
Error:
Expected Behavior
The code should compile without error, as it does at runtime. Per the Fetch API spec, the
Requestconstructor accepts eitherRequestInitor anotherRequestas the second parameter.Spec Reference
From Fetch Standard § 5.4:
The spec shows that
initcan be used alongside an existing Request to override specific properties while copying the rest.Use Case
This pattern is common when you need to clone a request but change its URL:
Current Workaround
Suggested Fix
Update the Request constructor type signature from:
To:
Environment
wrangler types(wrangler 4.44.0+)worker-configuration.d.ts