node-draftlog icon indicating copy to clipboard operation
node-draftlog copied to clipboard

Typescript compatibility

Open ilyasfoo opened this issue 6 years ago • 7 comments

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) => {}
    }
}

ilyasfoo avatar Mar 28 '19 00:03 ilyasfoo

good idea, can you make a merge request?

ivanseidel avatar Mar 30 '19 18:03 ivanseidel

interface Console {
    draft: (...args) => (b) => {}
}

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

elmarti avatar May 09 '19 15:05 elmarti

Is there any progress on this?

dominik-korsa avatar Apr 16 '20 14:04 dominik-korsa

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.

adelisle avatar Nov 12 '21 16:11 adelisle

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

kshutkin avatar Dec 02 '21 15:12 kshutkin

Running into issue @adelisle mentioned using [email protected]

trhinehart-godaddy avatar Feb 04 '22 23:02 trhinehart-godaddy

Running into issue @adelisle mentioned using [email protected]

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') : () => {};
}

oliviermoratin-rapid avatar Jan 06 '23 18:01 oliviermoratin-rapid