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 for pino.multistream #1152

Merged
merged 3 commits into from Oct 14, 2021
Merged

Fix types for pino.multistream #1152

merged 3 commits into from Oct 14, 2021

Conversation

clemyan
Copy link
Contributor

@clemyan clemyan commented Oct 12, 2021

Fixes TypeScript types for pino.multistream.

Also, the implementation of pino.multistream is actually pretty loose with the first argument. It can handle:

  • An object with stream and optionally level properties (i.e. a StreamEntry)
  • An object with a write method (i.e. a DestinationStream)
  • An array of the above

However, only array of StreamEntry is documented, and the current types reflect that. I don't know if that is intentional, so I have not changed that for now. If not, then the correct type should be (DestinationStream | StreamEntry)[] | DestinationStream | StreamEntry

@mcollina
Copy link
Member

could you add tests for the types? They live in: https://github.com/pinojs/pino/tree/master/test/types

@clemyan
Copy link
Contributor Author

clemyan commented Oct 12, 2021

Added tests.

How about the first argument? Should we change the types to more closely align with the actual implementation, or just stick to the documented JS usage?

@mcollina
Copy link
Member

Added tests.

Thanks

How about the first argument? Should we change the types to more closely align with the actual implementation, or just stick to the documented JS usage?

I'm lost. I think the types are ok as is, but maybe I'm missing some detail.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@clemyan
Copy link
Contributor Author

clemyan commented Oct 13, 2021

I'm lost. I think the types are ok as is, but maybe I'm missing some detail.

Well, in terms of the implementation, pino.multistream is pretty liberal with it first argument. Each of the following works as expected

pino.multistream(process.stdout) // Single stream
pino.multistream([process.stdout]) // Array of streams
pino.multistream({ stream: process.stdout, level: 'info' }) // Single StreamEntry
pino.multistream([{ stream: process.stdout, level: 'info' }]) // Array of StreamEntries

// Mixed array
pino.multistream([
	process.stdout,
	{ stream: process.stderr, level: 'error' },
]) 

However, only the "Array of StreamEntries" usage is documented. So the TypeScript types in this PR only allows array of StreamEntries. Question is whether the types should allow any or all of the other cases.

@mcollina
Copy link
Member

I think we should document all signatures and allow them in TS. Could you get them in?

@clemyan
Copy link
Contributor Author

clemyan commented Oct 14, 2021

I have added the other signatures to the types and tests.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit fc291b7 into pinojs:master Oct 14, 2021
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants