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

fix(types): correct CommonJS export in @fastify/otel typings #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bcomnes
Copy link

@bcomnes bcomnes commented Mar 17, 2025

The typescript typings were exporting using the ESM style exports, but this is a CJS module, so the exports were not resolving correctly. This switches the type export to use export = syntax instead which works for ESM consumers as well as CJS consumers.

Fixes #24

Checklist

The typescript typings were exporting using the ESM style exports, but this is a CJS module, so the exports were not resolving correctly. This switches the type export to use `export = ` syntax instead which works for ESM consumers as well as CJS consumers.

Fixes fastify#24

Signed-off-by: Bret Comnes <[email protected]>
Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add some tests for it? Check test/index.test-d.ts

@@ -16,5 +16,4 @@ declare class FastifyOtelInstrumentation<Config extends FastifyOtelInstrumentati
plugin (): (instance: FastifyInstance, opts: FastifyOtelOptions, done: (err?: Error) => void) => void
}

export default FastifyOtelInstrumentation
export { FastifyOtelInstrumentation }
export = FastifyOtelInstrumentation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot!

Is this enough? Should we export the default as other plugins do?

https://github.com/fastify/fastify-redis/blob/713d5019c5bcc7003a0cf42c13cae56551074332/types/index.d.ts#L37-L41

Copy link
Author

@bcomnes bcomnes Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall spotting other issues on other plugins, but also I import them into register in an fp so maybe I missed the issues. If it's an issue here, then it's also presumably an issue elsewhere. There might be other places where this is addressed, would need to investigate.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some tests using eg tsd?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@bcomnes
Copy link
Author

bcomnes commented Mar 17, 2025

can you add some tests for it? Check test/index.test-d.ts

Yes, I will add some when I find time on an evening. Anyone feel free to beat me to it.

@@ -16,5 +16,4 @@ declare class FastifyOtelInstrumentation<Config extends FastifyOtelInstrumentati
plugin (): (instance: FastifyInstance, opts: FastifyOtelOptions, done: (err?: Error) => void) => void
}

export default FastifyOtelInstrumentation
export { FastifyOtelInstrumentation }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no attempt at named exports afaict:

otel/index.js

Line 410 in 1f850f6

module.exports = FastifyOtelInstrumentation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bcomnes can you add the named export support?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript import example
5 participants