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

Use global Request type to prevent type errors #70

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

acusti
Copy link
Contributor

@acusti acusti commented Nov 19, 2024

this is branched off of #69 (which is branched off of #68) and removes all usage of the Request<unknown, IncomingRequestCfProperties<unknown>> type. at one point during work on #66, using that type resolved issues with the version of @cloudflare/workers-types available at that time and with usage of superflare’s handleFetch from the main worker.ts script, but that is no longer the case. in fact, these types are now causing the following TS error (from running tsc in the examples/remix-cms workspace):

worker.ts:17:37 - error TS2345: Argument of type 'Request<unknown, IncomingRequestCfProperties<unknown>>' is not assignable to parameter of type 'import("/Users/Redacted/Projects/superflare/node_modules/.pnpm/@[email protected]/node_modules/@cloudflare/workers-types/index").Request<unknown, import("/Users/Redacted/Projects/superflare/node_modules/.pnpm/@[email protected]/node_modules/@cloudflare/workers-types/index").Incomi...'.
  The types of 'clone().headers' are incompatible between these types.
    Property 'getAll' is missing in type 'Headers' but required in type 'import("/Users/Redacted/Projects/superflare/node_modules/.pnpm/@[email protected]/node_modules/@cloudflare/workers-types/index").Headers'.

17       return await handleFetch<Env>(request, env, ctx, config, handleRequest);

updating request type annotations to use the globally available Request type without any generics resolves the issue.

• build: { minify: true } causes variable names to be mangled in the SSR build of the app, which means that Models will have the wrong name and will wind up pointing at non-existent (or wrong) D1 tables
• v3_lazyRouteDiscovery is a new default behavior for remix that doesn’t require any other changes to enable
you need to pass the --remote flag to the newest version of wrangler’s migrations apply command in order to get it to run on the production instance of the D1 DB
also, upgrade from v3.6.1 → v3.8.0 (latest)
this resolves a type error that was being triggered when using handleFetch<env>(request, …) from a worker.ts script (e.g. in examples/remix-cms). the full TS error:

worker.ts:17:37 - error TS2345: Argument of type 'Request<unknown, IncomingRequestCfProperties<unknown>>' is not assignable to parameter of type 'import("/Users/andrew/Projects/superflare/node_modules/.pnpm/@cloudflare[email protected]/node_modules/@cloudflare/workers-types/index").Request<unknown, import("/Users/andrew/Projects/superflare/node_modules/.pnpm/@cloudflare[email protected]/node_modules/@cloudflare/workers-types/index").Incomi...'.
  The types of 'clone().headers' are incompatible between these types.
    Property 'getAll' is missing in type 'Headers' but required in type 'import("/Users/andrew/Projects/superflare/node_modules/.pnpm/@cloudflare[email protected]/node_modules/@cloudflare/workers-types/index").Headers'.

17       return await handleFetch<Env>(request, env, ctx, config, handleRequest);
Copy link

pkg-pr-new bot commented Nov 19, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/jplhomer/superflare@70
pnpm add https://pkg.pr.new/jplhomer/superflare/@superflare/remix@70

commit: 1f267c7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant