Skip to content
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

setBindings is no longer available on the typing of FastifyBaseLogger #4344

Closed
2 tasks done
silenceisgolden opened this issue Oct 17, 2022 · 5 comments · Fixed by #4346 or #4681
Closed
2 tasks done

setBindings is no longer available on the typing of FastifyBaseLogger #4344

silenceisgolden opened this issue Oct 17, 2022 · 5 comments · Fixed by #4346 or #4681
Labels
good first issue Good for newcomers typescript TypeScript related

Comments

@silenceisgolden
Copy link

silenceisgolden commented Oct 17, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the regression has not already been reported

Last working version

4.3.0

Stopped working in version

4.8.1

Node.js version

18.x

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

20.04

💥 Regression Report

FastifyLoggerInstance had a method called setBindings that I am using currently to preserve context across multiple log method calls. It looks like FastifyLoggerInstance was replaced with FastifyBaseLogger in #4224, but the typings (at least) show the method as missing when my typecheck runs in my CI checks:

// tsc --noEmit

> tsc --noEmit

src/_framework/context-from-params.ts:41:14 - error TS2339: Property 'setBindings' does not exist on type 'FastifyBaseLogger'.

41    state.log.setBindings(metadata);
                ~~~~~~~~~~~

src/_framework/context-from-request.ts:31:[16](<redacted>/actions/runs/3227392130/jobs/5282140045#step:5:17) - error TS2339: Property 'setBindings' does not exist on type 'FastifyBaseLogger'.

31    request.log.setBindings(metadata);
                  ~~~~~~~~~~~


Found 2 errors in 2 files.

Steps to Reproduce

Sorry that I cannot link to the project, but I think if you have a default simple fastify project that calls request.log.setBindings() in 4.3 and upgrade it to 4.8, the type checking should fail with a similar error as above.

Expected Behavior

I would expect that this method would be preserved in source code and types unless there was a major version change.

@silenceisgolden
Copy link
Author

👏🏻 to @BlackHole1, @climba03003 and @mcollina. Thanks for addressing this so quickly.

@BlackHole1
Copy link
Contributor

@silenceisgolden Sorry, we had to revert because this change triggered #4354. until we can think of a better way, you can use the following solution.

In fastify.d.ts file

declare module "fastify" {
    interface FastifyBaseLogger {
        setBindings(bindings: import("pino").Bindings): void;
    }
}

In tsconfig.json file

{
  "....": "...",
  "include": ["fastify.d.ts"]
}

@mcollina mcollina reopened this Oct 18, 2022
@tzafrirben
Copy link
Contributor

tzafrirben commented Apr 8, 2023

@mcollina Will this approach even work? FastifyBaseLogger is a type alias and not an interface

declare module "fastify" {
    interface FastifyBaseLogger {
        setBindings(bindings: import("pino").Bindings): void;
    }
}

I guess that my real question is why is FastifyBaseLogger not an interface so users can take advantage of declaration merging and extract them

@mcollina
Copy link
Member

I don't know, would you like to try a fix in a PR?

@tzafrir-benami-sage
Copy link

Agreed - I will try to create a commit according to contribution guide lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers typescript TypeScript related
Projects
None yet
6 participants