Skip to content

Improved Request type causing new type mismatch #2915

Open
@aaronadamsCA

Description

@aaronadamsCA

Since version 4.20241004.0, there is a Request type mismatch when using exactOptionalPropertyTypes.

Example 1

export default {
  async fetch(request) {
    const newRequest = new Request("newUrl", request);
    //                                       ^^^^^^^
    return fetch(newRequest);
  },
} satisfies ExportedHandler;
Argument of type 'Request<unknown, IncomingRequestCfProperties<unknown>>' is not assignable to parameter of type 'RequestInit<CfProperties<unknown>>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  Types of property 'cf' are incompatible.
    Type 'IncomingRequestCfProperties<unknown> | undefined' is not assignable to type 'CfProperties<unknown>'.
      Type 'undefined' is not assignable to type 'CfProperties<unknown>'.

Example 2

export default {
  async fetch(request) {
    const newRequest = new Request(request);
    return fetch("newUrl", newRequest);
    //                     ^^^^^^^^^^
  },
} satisfies ExportedHandler;
No overload matches this call.
  Overload 1 of 2, '(input: RequestInfo, init?: RequestInit<RequestInitCfProperties> | undefined): Promise<Response>', gave the following error.
    Argument of type 'Request<unknown, CfProperties<unknown>>' is not assignable to parameter of type 'RequestInit<RequestInitCfProperties>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
      Types of property 'cf' are incompatible.
        Type 'CfProperties<unknown> | undefined' is not assignable to type 'RequestInitCfProperties'.
          Type 'undefined' is not assignable to type 'RequestInitCfProperties'.
  Overload 2 of 2, '(input: RequestInfo | URL, init?: RequestInit<CfProperties<unknown>> | undefined): Promise<Response>', gave the following error.
    Argument of type 'Request<unknown, CfProperties<unknown>>' is not assignable to parameter of type 'RequestInit<CfProperties<unknown>>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
      Types of property 'cf' are incompatible.
        Type 'CfProperties<unknown> | undefined' is not assignable to type 'CfProperties<unknown>'.
          Type 'undefined' is not assignable to type 'CfProperties<unknown>'.

Metadata

Metadata

Labels

typesRelated to @cloudflare/workers-types

Type

No type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions