t3-oss / create-t3-turbo

Clean and simple starter repo using the T3 Stack along with Expo React Native
https://turbo.t3.gg
MIT License
4.69k stars 400 forks source link

bug: Type '{ __tag__: "GET"; __return_type__: unknown; }' does not satisfy the constraint '{ __tag__: "GET"; __return_type__: void | Response | Promise<void | Response>; } #800

Closed dBianchii closed 9 months ago

dBianchii commented 10 months ago

Provide environment information

ystem: OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa) CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-11390H @ 3.40GHz Memory: 4.72 GB / 15.36 GB Container: Yes Shell: 5.0.17 - /bin/bash Binaries: Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm pnpm: 8.10.2 - ~/.local/share/pnpm/pnpm bun: 1.0.2 - ~/.bun/bin/bun

Describe the bug

When running pnpm typecheck , sometimes I get this error:

@acme/nextjs:typecheck: .next/types/app/api/trpc/[trpc]/route.ts(59,7): error TS2344: Type '{ __tag__: "GET"; __return_type__: unknown; }' does not satisfy the constraint '{ __tag__: "GET"; __return_type__: void | Response | Promise<void | Response>; }'.
@acme/nextjs:typecheck:   Types of property '__return_type__' are incompatible.
@acme/nextjs:typecheck:     Type 'unknown' is not assignable to type 'void | Response | Promise<void | Response>'.
@acme/nextjs:typecheck: .next/types/app/api/trpc/[trpc]/route.ts(176,7): error TS2344: Type '{ __tag__: "POST"; __return_type__: unknown; }' does not satisfy the constraint '{ __tag__: "POST"; __return_type__: void | Response | Promise<void | Response>; }'.
@acme/nextjs:typecheck:   Types of property '__return_type__' are incompatible.
@acme/nextjs:typecheck:     Type 'unknown' is not assignable to type 'void | Response | Promise<void | Response>'.
@acme/nextjs:typecheck: .next/types/app/static/page.ts(2,24): error TS2307: Cannot find module '../../../../src/app/static/page.js' or its corresponding type declarations.
@acme/nextjs:typecheck: .next/types/app/static/page.ts(5,29): error TS2307: Cannot find module '../../../../src/app/static/page.js' or its corresponding type declarations.
@acme/nextjs:typecheck:  ELIFECYCLE  Command failed with exit code 1.
@acme/nextjs:typecheck: ERROR: command finished with error: command (/home/gabriel/Documents/Github/create-t3-turbo/apps/nextjs) /home/gabriel/.local/share/pnpm/pnpm run typecheck exited (1)
@acme/nextjs#typecheck: command (/home/gabriel/Documents/Github/create-t3-turbo/apps/nextjs) /home/gabriel/.local/share/pnpm/pnpm run typecheck exited (1)

The weird thing, ist that that sometimes this error does not appear. This is also happening on a fork I made. Happens on github CI as well for me.

Link to reproduction

I might add one later

To reproduce

Run pnpm typecheck after installing dependencies

Additional information

No response

juliusmarminge commented 10 months ago

I think this is actually next-auth's fault since they use the internal type AppRouteHandlerFn which expects unknown. I'll check with Balazs

dBianchii commented 10 months ago

I think this is actually next-auth's fault since they use the internal type AppRouteHandlerFn which expects unknown. I'll check with Balazs

Yes. I fiddled around for a while, and it's exactly the return type of auth() that is causing the problem.

nnad3N commented 9 months ago

Is there a way to fix the typescript error?

UPDATE: I just casted the auth() route handler as (req: NextRequest) => Promise<Response>. I don't think it should cause any problems, but I might be wrong.

juliusmarminge commented 9 months ago

should be fixed