TypeScript issue when passing Pino instance to fastify constructor
Author: pavelkornevCreated Aug 8, 2023Updated Sep 17, 2026
Labelsbugtypescript
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.21.0
Plugin version
No response
Node.js version
18.14.2
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
13.5
Description
By some historical reasons we pass a Pino instance to fastify factory function (I'm aware that Pino is built-in into fastify):
const logger = pino({
// ...some config
});
const server = fastify({
logger,
// ...other opts
});
But starting v4.20.0 this code is no longer working with the following TypeScript compile error:
Type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, Logger<LoggerOptions | DestinationStream>, FastifyTypeProviderDefault>' is not assignable to type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>'.
The types of 'withTypeProvider().childLoggerFactory' are incompatible between these types.
Type 'FastifyChildLoggerFactory<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, Logger<LoggerOptions | DestinationStream>, any>' is not assignable to type 'FastifyChildLoggerFactory<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, any>'.
The 'this' types of each signature are incompatible.
Type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, any>' is not assignable to type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, Logger<LoggerOptions | DestinationStream>, any>'.
Types of property 'log' are incompatible.
Type 'FastifyBaseLogger' is not assignable to type 'Logger<LoggerOptions | DestinationStream>It seems to be related to this recent change - https://github.com/fastify/fastify/pull/4760
Steps to Reproduce
- Create Pino instance
- Try to pass to
fastifyfactory function
Expected Behavior
No response
Source: fastify/fastify