Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Request type causing new type mismatch #2915

Open
aaronadamsCA opened this issue Oct 13, 2024 · 0 comments
Open

Improved Request type causing new type mismatch #2915

aaronadamsCA opened this issue Oct 13, 2024 · 0 comments
Assignees
Labels
types Related to @cloudflare/workers-types

Comments

@aaronadamsCA
Copy link

As of 4.20241004.0, and still in 4.20241011.0, the updated Request type introduced a small 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>'.
@aaronadamsCA aaronadamsCA added the types Related to @cloudflare/workers-types label Oct 13, 2024
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Oct 13, 2024
@aaronadamsCA aaronadamsCA changed the title New type mismatch in not assignable to type 'CfProperties<unknown>'. Improved Request type causing new type mismatch Oct 13, 2024
@andyjessop andyjessop moved this from Untriaged to Backlog in workers-sdk Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types Related to @cloudflare/workers-types
Projects
Status: Backlog
Development

No branches or pull requests

2 participants