fastify / fastify-plugin

Plugin helper for Fastify
MIT License
202 stars 43 forks source link

Typescript error on usage #105

Closed RafaelGSS closed 4 years ago

RafaelGSS commented 4 years ago

🐛 Bug Report

fastify-plugin + fastify on typescript not work as expected. I understand the problem when this doc was created: https://github.com/fastify/fastify-plugin#known-issue-typescript-contextual-inference, but following the examples not works as well. I created a reproduction code https://github.com/RafaelGSS/fastify-fp-types.

To Reproduce

https://github.com/RafaelGSS/fastify-fp-types

Expected behavior

Not throw an error on runtime because of the wrong transpilation

Your Environment

fox1t commented 4 years ago

OK the issue is related to the fact that the code compiles as fastify_plugin_1["default"](examplePlugin) and there is not exported default prop here https://github.com/fastify/fastify-plugin/blob/master/plugin.js#L125 To fix this is enough to add plugin.default = plugin before module.exports = plugin.