-
-
Notifications
You must be signed in to change notification settings - Fork 67
docs(examples): Fix ineffective TypeScript example #350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Stanislav (Stanley) Modrak <[email protected]>
Signed-off-by: Stanislav (Stanley) Modrak <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the TypeScript example in the QuickStart component to improve type safety and add server startup logging.
- Added explicit generic type parameters to
FastifyInstancefor better TypeScript type safety - Enabled logger in the Fastify initialization
- Added server startup log message to inform users when the server is listening
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { Server, IncomingMessage, ServerResponse } from 'http' | ||
| const server: FastifyInstance = Fastify({}) | ||
| const server: FastifyInstance<Server, IncomingMessage, ServerResponse> = Fastify({ logger: true }) |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The explicit generic type parameters <Server, IncomingMessage, ServerResponse> are unnecessary in modern Fastify TypeScript usage. Fastify v4+ has improved type inference and these generics are deprecated. The simpler const server: FastifyInstance = Fastify({ logger: true }) is the recommended approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDK 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Eomm I know that's the case (the types are inferred since v4+). But this code block is meant to be a trivial code example. Of which the whole purpose was just to demonstrate TypeScript typing compatibility of Fastify. This is still hugely better than it was before, which had floating unused imports appearing in a code block, with no apparent use (and breaking TypeScript lint rules). As well as the accompanying text not logically relating to the code example. Otherwise, the whole code block should just be removed completely (as it doesn't demonstrate anything and actually breaks good practices).
I am not sure how much Copilot feedback is relevant here as this is meant to be a training article. It likely misses that the point here is "demonstration".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be useful to add a comment line // from Fastify v4 these types are inferred automatically, you may omit them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Eomm btw, Copilot is wrong here, this generic is not deprecated, it's just inferred and not necessary to type in, but the type generic is still used and is very much valid
| const address = server.server.address() | ||
| const port = typeof address === 'string' ? address : address?.port | ||
| server.log.info(`Server listening on port ${port}`) |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error: Unexpected token
| const address = server.server.address() | ||
| const port = typeof address === 'string' ? address : address?.port | ||
| server.log.info(`Server listening on port ${port}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| server.log.info(`Server listening on port ${port}`) | |
| server.log.info('Server listening on port %s', port) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure? All other examples in the docs prefer to use ${x} type of interpolation (e.g. https://fastify.dev/docs/latest/Guides/Getting-Started/). We should ensure consistency.
| import { Server, IncomingMessage, ServerResponse } from 'http' | ||
| const server: FastifyInstance = Fastify({}) | ||
| const server: FastifyInstance<Server, IncomingMessage, ServerResponse> = Fastify({ logger: true }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDK 😂
Description
This fixes the currently very ineffective and (imo) broken TypeScript use example.
Issues addressed:
portto show how one would get the portold version:

Related Issues
Check List