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

Example of how to use tracer with TypeScript #139

Open
basharov opened this issue May 20, 2023 · 3 comments
Open

Example of how to use tracer with TypeScript #139

basharov opened this issue May 20, 2023 · 3 comments

Comments

@basharov
Copy link

basharov commented May 20, 2023

I see type definitions in the package, but when I try to import and use this way:

import { colorConsole } from 'tracer'

const logger = colorConsole({})
console.error('some error')

It says Property 'error' does not exist on type 'Logger<"error">.

Can you provide some simple example of how to properly import and use tracer with TypeScript?

Thanks!

@Kreedzt
Copy link

Kreedzt commented Aug 2, 2023

It is missing the ts type definition, so we need to do it ourselves.

import * as tracer from 'tracer';

export const logger = tracer.dailyfile({
    root: './logs',
    maxLogFiles: 20,
    transport: [
        function (data) {
            console.log(data.output)
        }
    ]
}) as {
    info: (...args: any[]) => void,
    warn: (...args: any[]) => void,
    debug: (...args: any[]) => void,
    error: (...args: any[]) => void,
    log: (...args: any[]) => void,
};

@baryon
Copy link
Owner

baryon commented Sep 13, 2023

We have upgraded tracer to version 1.2.0, incorporating declarations for dynamically adding functions to objects. However, we are still facing an issue where ESLint perceives these functions as potentially being undefined. Using an exclamation mark after each function reference feels inelegant. If anyone has a solution to this problem, please submit a patch.

@JulesGuesnon
Copy link

Hello! I just found out about the library and this issue as well. I would be glad to fill a PR, but I don't get what you mean by incorporating declarations for dynamically adding functions to objects. If you don't mind taking some time to show me an example of what you want to achieve, I could help implementing it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants