When using Fastify v5.6.2 with TypeScript and fastify-socket.io, the io property is not recognized by TypeScript, even though it exists at runtime.
Error:
error TS2339: Property 'io' does not exist on type 'FastifyInstance<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault> & PromiseLike<...> & { ...; }'
error reproduce:
import fastify from "fastify";
import fastifyIO from "fastify-socket.io";
const server = fastify();
server.register(fastifyIO);
server.get("/", (req, reply) => {
server.io.emit("hello");
});
server.ready().then(() => {
// we need to wait for the server to be ready, else `server.io` is undefined
server.io.on("connection", (socket) => {
// ...
});
});
server.listen({ port: 3000 });
official socket.io docs: link
When using Fastify v5.6.2 with TypeScript and fastify-socket.io, the io property is not recognized by TypeScript, even though it exists at runtime.
Error:
error reproduce:
official socket.io docs: link