I am currently in the process of creating a REST API using Fastify, and I have encountered a TypeScript error that is causing some trouble:
An incompatible type error has occurred while trying to add a handler for the 'generateQrCode' route. The specific details of the error are related to parameter types and property assignments within the code structure.
Here is the snippet of code where the error surfaces, specifically when adding the handler for the generateQrCode
route:
import { RouteOptions } from "fastify";
import pingServer from "../controllers/pingServer";
import generateQRCode from "../controllers/generateQrCode";
const ping: RouteOptions = {
method: "GET",
url: "/ping",
handler: pingServer,
};
const generateQrCode: RouteOptions = {
method: "POST",
url: "/generate",
handler: generateQRCode,
};
const routes = [ping];
export default routes;
The code snippet for the controller of that particular route looks like this:
import { FastifyRequest, FastifyReply } from "fastify";
import { encodeURL, TransactionRequestURLFields } from "@solana/pay";
import { nanoid } from "nanoid";
// Additional imports...
const generateQRCode = async (request: FastifyRequest<{ Body: IGenerateQRCode; }>, reply: FastifyReply) => {
// Code logic for generating QR codes
};
export default generateQRCode;
// Interface used in the controller's code
export interface IGenerateQRCode {
candyMachineId: string;
network: string;
rpcUrl: string;
label: string;
icon: string;
message: string;
}
I suspect the issue lies with how generics are handled, but I am currently unable to pinpoint the exact solution.