maraisr / diary

📑 Zero-dependency, fast logging library for Node, Browser and Workers
MIT License
252 stars 7 forks source link

`LogFnAsError` type missing from `src/index.d.ts` #20

Closed maxmilton closed 2 years ago

maxmilton commented 2 years ago

Describe the bug

After https://github.com/maraisr/diary/commit/78334b38ac7a41e33169562c17829933fd2479b9 the types in https://github.com/maraisr/diary/blob/a723e0b203321faa6a95195c9991c2cf74c67427/src/index.d.ts are broken. Specifically, a type definition for LogFnAsError is now missing.

This means that any use of customLogger.error(...) and customLogger.fatal(...) in a typescript project doesn't work as expected.

To reproduce

import { diary } from 'diary';

const customLogger = diary('');

customLogger.error(new Error('test'));

Typescript can't see any type definition for LogFnAsError and treats it as any. When using @typescript-eslint/eslint-plugin in a project, a lint error for the rule @typescript-eslint/no-unsafe-call is emitted for customLogger.error.

Expected behavior

customLogger.error(...) and customLogger.fatal(...) are typed correctly.

maxmilton commented 2 years ago

Created a fix PR in https://github.com/maraisr/diary/pull/21.

I also suggest adding linting to this project which would catch bugs like this.

maraisr commented 2 years ago

Yeah ouch... bad moment! Sorry about this. Ill get this out asap.

In terms of testing, yeah think I better — this hasn't been the first time. Thanks for jumping on it.

maraisr commented 2 years ago

I think with this commit (https://github.com/maraisr/diary/commit/707d6873a98b3982696fa750e8973e7fcfdc24d3) we should now have tests for our types as well.

Thanks for the highlight.

also v0.4.3 has the fix applied.