Hi there, i'm using Fastify & Typescript on my pro...
# support-questions-legacy
d
Hi there, i'm using Fastify & Typescript on my project. I wanted to create a simple route with a request param
/:id
, but can't figure out how to use both SessionRequest object and add my params type on it:
Copy code
fastify.get("/:id", { preHandler: verifySession() }, async (request: SessionRequest<{ params: { id: int } }>, reply) => {
This doesn't work and typescript throw me a biiiig error explaining it can't accept this argument... Do you have any idea ?
I'm not really used to type like that yet, so I might miss something important and/or basic.. ^^
Okay, i might have fixed it by creating 2 interfaces:
Copy code
typescript
interface ChallengeParams {
    id: string
}

interface ChallengeRequest extends SessionRequest {
    params: ChallengeParams
}
// ...
fastify.get<{ Params: ChallengeParams }>("/:id", { preHandler: verifySession() }, async (request: ChallengeRequest, reply) => {
But it makes the whole things hard to read i guess...
4 Views