ivanseidel / node-draftlog

📜 Create mutable log lines into the terminal, and give life to your logs!
MIT License
1.25k stars 34 forks source link

Typescript compatibility #7

Open ilyasfoo opened 5 years ago

ilyasfoo commented 5 years ago

Because this module extends functionality of Console, the following is required to avoid typescript complaining about missing "draft" function:

interface Console {
        draft: (a) => (b) => {}
}

I think to support this from the module level, we can use the global declaration feature

declare global {
    interface Console {
        draft: (a) => (b) => {}
    }
}
ivanseidel commented 5 years ago

good idea, can you make a merge request?

elmarti commented 5 years ago
interface Console {
    draft: (...args) => (b) => {}
}

Works for me as I leverage the console ...args setup

dominik-korsa commented 4 years ago

Is there any progress on this?

adelisle commented 3 years ago

I'm having an issue building a typescript project containing the recently published version 1.0.13 containing the merged #8.

node_modules/draftlog/index.d.ts:15:5 - error TS1038: A 'declare' modifier cannot be used in an already ambient context.

15     declare function into(console: Console, extra?: boolean): LineCountStream;
       ~~~~~~~

Found 1 error.

Removing that superfluous declare fixes this issue.

kshutkin commented 2 years ago

tested draftlog 1.0.13 with rollup / rollup-plugin-typescript2. I have no problems and everything works perfectly regarding typescript compatibility.

trhinehart-godaddy commented 2 years ago

Running into issue @adelisle mentioned using typescript@4.5.5

oliviermoratin-rapid commented 1 year ago

Running into issue @adelisle mentioned using typescript@4.5.5

I wrapped the call with something like this and it works

const logUpdate = (msg: string): void => {
  return 'draft' in console && typeof console.draft === 'function' ? console.draft('test') : () => {};
}