Skip to content

How to use a generic with decorators #372

Answered by L2jLiga
oof2win2 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi there, I think you are asking about specifying generics for FastifyRequest, the answer is

@Controller({ route: "/rules" })
export default class RuleController {
	@GET({
		url: "/:id", options: {
			schema: {
				params: Type.Required(Type.Object({
					id: Type.String()
				}))
			}
		}
	})
	async getRule(req: FastifyRequest<{ Params: { id: string } }>, res: FastifyReply) {
		const { id }: { id: string } = <any>req.params
	}
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@oof2win2
Comment options

Answer selected by oof2win2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants