Skip to content

Conversation

@mauriciabad
Copy link

withAxiomRouteHandler used to return always NextResponse<unknown>, it was giving me errors in my project.
I also added generics to the other withAxios function, that had the same problem.
And finally, now that the type inference is improved, there's no need to explicitly say that req is AxiomRequest, so I updated the example's code.

Warning

Be aware that I used a type cast that could be unsafe (as T in line 99), because I couldn't manage to do it in any other way. Maybe someone more experienced in TypeScript can find a better solution, but for now, mine is "good enough".

@vercel
Copy link

vercel bot commented Oct 26, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-axiom-example ❌ Failed (Inspect) Jan 27, 2024 7:31am

throw error;
}
};
}) as T;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the unsafe cast I mean.

If you do this, which would be the proper way, there is a type error I can't fix:

export function withAxiomRouteHandler<T extends AxiomHandler>(handler: T): T {
  const result: T = async (req, arg) => { ... }
  return result
}
Type '(req: AxiomRequest, arg: any) => Promise<Response | NextResponse<unknown>>' is not assignable to type 'T'.
  '(req: AxiomRequest, arg: any) => Promise<Response | NextResponse<unknown>>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'AxiomHandler<any, Response | NextResponse<unknown>>'.ts(2322)

@thesollyz thesollyz added bug Something isn't working help wanted Extra attention is needed labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants