Skip to content

chore: use TSTyche for type testing#650

Merged
mcollina merged 7 commits intopinojs:masterfrom
mrazauskas:use-tstyche
Mar 27, 2026
Merged

chore: use TSTyche for type testing#650
mcollina merged 7 commits intopinojs:masterfrom
mrazauskas:use-tstyche

Conversation

@mrazauskas
Copy link
Copy Markdown
Contributor

@mrazauskas mrazauskas commented Mar 16, 2026

Similar to pinojs/pino#2376

This PR migrates type test to TSTyche.

Current type test file is rather short (only 58 lines). I took the opportunity and wrote the tests from scratch. This way I could use test() helper to organise the tests and to cover all public types with tests.

Linting for .ts files also got enabled. I hope this is not too much to review.


The test() helper is one of the advantages of TSTyche. You can use .skip or .only with it.

Also you can test types against specific TypeScript version. For example, tstcyhe --target next.

And much more: https://tstyche.org

Comment thread index.d.ts
import { DestinationStream, Level } from 'pino'
import * as Colorette from 'colorette'

type LogDescriptor = Record<string, unknown>;
Copy link
Copy Markdown
Contributor Author

@mrazauskas mrazauskas Mar 16, 2026

Choose a reason for hiding this comment

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

LogDescriptor was used only once, so I moved it inline. Otherwise it should be exported, but would that be useful?

Comment thread index.d.ts
}

function build(options: PrettyOptions): PrettyStream;
export function build (options?: PrettyOptions): PrettyStream
Copy link
Copy Markdown
Contributor Author

@mrazauskas mrazauskas Mar 16, 2026

Choose a reason for hiding this comment

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

Seems like here options must be optional. Same as #327

Comment thread index.d.ts
Comment on lines -225 to -227
type ColorizerFactory = typeof colorizerFactory;
type PrettyFactory = typeof prettyFactory;
type Build = typeof build;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These three types are not used and not exported. Can be removed. ESLint detected that.

Comment thread package.json
"lint:fix": "eslint --fix",
"test": "borp",
"test-types": "tsc && tsd && attw --pack .",
"test:types": "tstyche && attw --pack .",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is no need to run tsc, because TSTyche does check .d.ts files as well.

Comment thread index.d.ts
type Build = typeof build;
type PrettifierExtras = { colors: Colorette.Colorette, label: string, labelColorized: string }
export type Prettifier = (inputData: string | object, key: string, log: object, extras: PrettifierExtras) => string
export type MessageFormatFunc = (log: Record<string, unknown>, messageKey: string, levelLabel: string, extras: Pick<PrettifierExtras, 'colors'>) => string
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Signature is updated to align with behaviour:

const msg = messageFormat(log, messageKey, levelLabel, { colors: colorizer.colors })

@mrazauskas
Copy link
Copy Markdown
Contributor Author

Sorry, I had some second thoughts. The code is updated and ready for review.

Copy link
Copy Markdown
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 a7d31e1 into pinojs:master Mar 27, 2026
5 checks passed
@mrazauskas mrazauskas deleted the use-tstyche branch March 28, 2026 05:40
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.

2 participants