"Promise<NextResponse<{ codes: number; }>>" is not a valid GET return type
Answered
American posted this in #help-forum
AmericanOP
What am I doing wrong here?
full error:
import { NextResponse } from "next/server";
export const dynamic = "force-dynamic";
export const GET = async () => {
return NextResponse.json({ codes: 1 });
};full error:
Checking validity of types ...Failed to compile.
src/app/api/automation/cleanup/route.ts
Type error: Route "src/app/api/automation/cleanup/route.ts" has an invalid export:
"Promise<NextResponse<{ codes: number; }>>" is not a valid GET return type:
Expected "void | Response | Promise<void | Response>", got "Promise<NextResponse<{ codes: number; }>>".
Expected "Promise<void | Response>", got "Promise<NextResponse<{ codes: number; }>>".
Expected "void | Response", got "NextResponse<{ codes: number; }>".23 Replies
you are using latest nextjs version right?
AmericanOP
Yes, 14.0.3
also can you try
return NextResponse.json({ codes: 1 }) as Response; (this may work but is a little sus)AmericanOP
Type 'NextResponse<{ codes: number; }>' is missing the following properties from type 'Response': headers, ok, redirected, status, and 11 more
ahh
i mean, can you try with just Response and not NextReponse (it isn't nessary for json anymore)
AmericanOP
That works, but I can't make vscode be on a version of typescript that understands it
@American > Type 'NextResponse<{ codes: number; }>' is missing the following properties from type 'Response': headers, ok, redirected, status, and 11 more
lol i was about to say just put an
as any to make it quietAnswer
AmericanOP
It's like I'm stuck in bleeding edge hell
ðŸ˜
AmericanOP
any works, I guess I'll do that for now, cheersnice
but id say see if there is a gh issue or create it, as its kinda bad that it doesn't do as intended
also have you tried canary (i doub;t it fixes it, but it may)
AmericanOP
I haven't, but I might
Thanks for taking the time!
Should I mark it as answered or no, what do you think?
honestly whatever you think...
if im being honest, it doesn't really change much... but google may care more about that you select
AmericanOP
technically it's "a" solution, so I did it
AmericanOP
I tried that, but vscode doesn't pick up on it :(
sounds like a way separate issue but ðŸ˜