Skip to content

Use global Request type to prevent type errors - #70

Merged
jplhomer merged 10 commits into
jplhomer:mainfrom
acusti:request-type
Dec 17, 2024
Merged

Use global Request type to prevent type errors#70
jplhomer merged 10 commits into
jplhomer:mainfrom
acusti:request-type

Conversation

@acusti

@acusti acusti commented Nov 19, 2024

Copy link
Copy Markdown
Contributor

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/@cloudflare+workers-types@4.20241018.0/node_modules/@cloudflare/workers-types/index").Request<unknown, import("/Users/Redacted/Projects/superflare/node_modules/.pnpm/@cloudflare+workers-types@4.20241018.0/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/@cloudflare+workers-types@4.20241018.0/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+workers-types@4.20241018.0/node_modules/@cloudflare/workers-types/index").Request<unknown, import("/Users/andrew/Projects/superflare/node_modules/.pnpm/@cloudflare+workers-types@4.20241018.0/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+workers-types@4.20241018.0/node_modules/@cloudflare/workers-types/index").Headers'.

17       return await handleFetch<Env>(request, env, ctx, config, handleRequest);
@pkg-pr-new

pkg-pr-new Bot commented Nov 19, 2024

Copy link
Copy Markdown

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

@jplhomer
jplhomer merged commit ae0e7f1 into jplhomer:main Dec 17, 2024
@acusti
acusti deleted the request-type branch December 18, 2024 16:09
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.

2 participants