Pino: Proposal: bundle type definitions in Pino itself

Created on 14 Sep 2020  路  21Comments  路  Source: pinojs/pino

References

I found some prior talkings about this: https://github.com/pinojs/pino/issues/344

Background

I am opening this issue since we have currently a problem in the Fastify codebase: https://github.com/fastify/fastify/pull/2550

TLDR;

Fastify relies on Pino for logging and therefore also Fastify's typing has to reference Pino's one. The issue is that at the present day they aren't maintained by Pino's team and we are not going to include 3rd party typings in Fastify codebase.

Possible solution

If the Pino core team agree I can actively maintain typings inside this repo with the help of some other fastify core team members:

I am opening this issue because far as I can see, we don't have any other viable solution for the issue https://github.com/fastify/fastify/pull/2550

Most helpful comment

I'm fine with this as long as

  • out of sync/lack of TS definitions do not block PR's
  • if an issue regarding TS definitions is opened and not addressed and closed out in 30 days, we remove the definitions - and release that removal in a minor (since TS itself is fine with breaking changes in minor I don't think this is outlandish)

All 21 comments

Please describe what this would look like. Let's pretend I add a new hook in the same vein as the logMethod hook:

https://github.com/pinojs/pino/blob/db651a51762e8b043f406a73bb19470bcf6dcff1/docs/api.md#L172-L196

Are you going to come along and update the types before the PR is committed? After? If after, do we now have to delay releases until a TS person does their thing?

How do these TS pull requests get reviewed? I can't review them. Matteo probably can't effectively review them. Likely not David either.

Why are these types even needed? From https://web.archive.org/web/20200912101819/https://www.typescriptlang.org/:
TypeScript: Typed JavaScript at Any Scale  - Vivaldi 2020-09-14 10-07-54

That says to me you shouldn't ever need some TS specific file to use Pino, regardless of where you use Pino.

I'm ok in adding native types if we have 2 people willing to come on board and review them, keeping them as a separate thing (similar to fastify).

I think that the process might be very similar to Fastify's one: we can schedule a release and then work all together on delivering it.

Speaking on the screenshot you provided, it isn't applicable here because Fastify already ships the typings, so we are already effectively responsible for providing the correct ones. We can just put unknown as Pino types, but it is the worst possible developer experience and we should avoid it, if possible.

馃憢 Hi, I'm willing to review & maintain type definitions. DefinitelyTyped is works well for what it is, but the separation between package maintainers and type definition maintainers results in perpetual drift and inaccuracies, so (as a pino & TS user / contributor) I think this is a worthwhile investment.

I am willing to participate in review and maintenance as well.

I'm fine with this as long as

  • out of sync/lack of TS definitions do not block PR's
  • if an issue regarding TS definitions is opened and not addressed and closed out in 30 days, we remove the definitions - and release that removal in a minor (since TS itself is fine with breaking changes in minor I don't think this is outlandish)
  • if an issue regarding TS definitions is opened and not addressed and closed out in 30 days, we remove the definitions - and release that removal in a minor

/highfive

if an issue regarding TS definitions is opened and not addressed and closed out in 30 days, we remove the definitions - and release that removal in a minor

This is a very interesting policy idea. I wonder how it could help other projects that are hesitant to adopt native type support (node-tap comes to mind). I'll be keeping an eye on how it goes for Pino 馃槃


I also want to add one note: why not the few here that are willing to maintain Pino types do so in DefinitelyTyped? The testing and release infrastructure already exists and it seems like there is a lengthy list of existing contributors. Might be better to collaborate with them on DT than start again here.

@Ethan-Arrowood Personally I hate the whole flow of contributing to DefinitelyTyped, but then again, I'm not a fan of monorepos in general.

@kibertoad understandable, but it has gotten better. They've put a lot of work into the bot so things are more automatic. If you have any direct feedback please let me know and I can forward it along

@Ethan-Arrowood Automation is not an issue, I would say that the whole concept of having to checkout a gajillion of folders to fix one interface, as well as having a crowded issue/pr space feels very messy to me.

It was quite intimidating to many developers on my team who are not to used to contributing to OSS, from which I can derive there must be a non-zero number of developers out there who might have contributed, but didn't, because from the outside it looks complex.

Also from developer experience perspective, not having another dependency to worry about is definitely convenient.

Also from developer experience perspective, not having another dependency to worry about is definitely convenient.

totally agree

It was quite intimidating to many developers on my team who are not to used to contributing to OSS

this is good feedback and perspective

having to checkout a gajillion of folders to fix one interface

Try using partial clone/checkout next time (https://git-scm.com/docs/partial-clone)

@Ethan-Arrowood I use WebStorm for everything Git. Thanks for the reference, will check if it's supported from IDE. It definitely would make a DT experience more pleasant.

There's no answer for this that satisfies everyone:

  1. The @types project is a pox that makes life miserable for maintainers who couldn't care less about TS.
  2. Adding types here will annoy the hell out of at least one maintainer.
  3. The TS project either lies (see above) or the people writing TS are incapable of making that language work as advertised so they will complain to no end at JavaScript projects that don't cater to them.

It's a shitshow no one maintains JavaScript projects asked for.

image

@jsumners I can see how the popularity of TypeScript and DefinitelyTyped can be a bane to pure JS maintainers due to the growing expectations that users have for type definitions to be available for popular packages, placing an unfair expectation on package maintainers to provide type definitions...

Ultimately, developers want a tight feedback loop that helps them use packages correctly.

JSDoc has long been a popular way for package authors to provide this feedback to editors (and to automatically generate API documentation). TypeScript has even recently added support for generating type definitions from JSDoc comments.

TypeScript gives a lot of us leverage over large applications, not just while editing, but by having checks run during CI, we save a lot of time by preventing hard to catch mistakes in interface usage from slipping through. That leverage doesn't hinge on a single package, but it does accumulate package by package.

Given that pino doesn't already have JSDoc comments, I wouldn't suggest going that route simply to avoid TypeScript type definitions, but if that's something you'd find more appealing by sharing the benefits with pure JS consumers, it might be worth considering.

Since I am the one who opened this issue, I think I need to clarify some points.

I perfectly understand why seeing an issue titled "Proposal: bundle type definitions in Pino" isn't the best issue a maintainer could find on the project board: if he/she/they cared about typings, the types would be there already or at least there would be an issue opened by the maintainer, asking for help.

However, in this specific case, the issue that led to this proposal was raised in Fastify. I here because @mcollina suggested me to ask here if there was any interest in adding types directly to the project.

Fastify team agrees that we don't want Fastify to rely upon a package (@types/pino) we don't have control over. At the moment, to get around this problem, as @Ethan-Arrowood pointed out, we are shipping a "minimal viable type API for the logger". Since Pino is the logger used by Fastify and there is some overlap between the two teams, it seemed natural to me to ask if I and others could help to maintain Pino's types: it was basically a win-win situation to me.

Moreover, @types/pino is downloaded 191,826 times per week (https://www.npmjs.com/package/@types/pino) and I saw this as a great opportunity to provide a better developer experience to developers that prefer to use TypeScript.

@Ethan-Arrowood, of course, we should help with @types/pino too but it will not resolve the issue that led to this proposal. This all started because of the _"we don't want Fastify to rely upon a package (@types/pino) we don't have control over"_ part and maintaining @types/pino wouldn't fix this problem, unless we agree it will. :/

@davidmarkclements I am absolutely fine with both of your points! Types haven't to be a point of friction for the maintainers that don't care about them. :)

As a final note, I want to address @jsumners concerns:

  1. it makes life miserable also to maintainers/developers who care about TS since @types is just an imperfect fallback that more often than not brings a ton of problems;
  2. I am sorry to annoy you. I swear it wasn't my intention. It all started when I saw the Fastify's issue and I realized this could be one of the possible solutions;
  3. As I already said, your assumption isn't correct for this specific case. Documentation doesn't lie and the people aren't incapable of making the language work as advertised. Since Fastify ships its typings, that paragraph isn't applicable to our own case: if there weren't any shipped types by fastify, we wouldn't have anything to fix and I wouldn't make this proposal. At the moment we are shipping partial typings: this is worse than not having them at all.

__If adding types here isn't viable then we should probably just close this issue and accept that the best possible developer experience isn't achievable.__

Again, sorry for bothering you all. Since I see some hatred about TS, next time I will be more careful in opening this kind of issues. Peace and love! 鉁岋笍

If you can show me how to correctly write JSDoc for factory functions and the composed objects they return, I'd be all for that. But I'll be quite shocked if you can show it's possible.

I see a two to one vote in favor of inclusion. One vote in favor suggests a viable way to trial the inclusion.

FYI: I had no idea that conversation was happening in the Fastify issues because I mute every TS related issue that comes in as soon as I see it.

I see a two to one vote in favor of inclusion. One vote in favor suggests a viable way to trial the inclusion.

FYI: I had no idea that conversation was happening in the Fastify issues because I mute every TS related issue that comes in as soon as I see it.

That's why I included that issue here for reference. :)

Good points @fox1t I'm always +1 for types, but I've learned it can be a point of contention too.

As I originally stated I think @davidmarkclements idea is really good! I'm looking forward to seeing how things develop 馃榿

I think at this point it's down to whomever wants to do it to submit the PR.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mcollina picture mcollina  路  3Comments

NicolaiSchmid picture NicolaiSchmid  路  4Comments

yoshuawuyts picture yoshuawuyts  路  5Comments

cekvenich picture cekvenich  路  6Comments

afgallo picture afgallo  路  4Comments