signale icon indicating copy to clipboard operation
signale copied to clipboard

WriteStream object is not accepted in stream array

Open tautf opened this issue 3 years ago • 1 comments

Describe the bug A clear and concise description of what the bug is.

private logFile: WriteStream = fs.createWriteStream(process.cwd() + path.join('////', 'logs', 'watchguard.txt'), {
            flags: 'a',
            encoding: 'utf8',
            autoClose: true
        });

is not accepted in SignaleOptions as stream.

To Reproduce Steps to reproduce the behavior.

Create an object of type SignaleObject and at the above as a stream into the array.

Expected behavior A clear and concise description of what you expected to happen. WritableStream is accepted.

Technical Info (please complete the following information)

  • OS: MacOS latest
  • Signale Version: 1.4.0 / @types/signale: 1.4.1
  • Node.js Version: 15.14

Additional context Add any other context about the problem here.

private logFile: WriteStream = fs.createWriteStream(process.cwd() + path.join('////', 'logs', 'watchguard.txt'), {
            flags: 'a',
            encoding: 'utf8',
            autoClose: true
        });

private options: SignaleOptions = {
        disabled: false,
        interactive: false,
        logLevel: process.env.LOG_LEVEL,
        scope: '',
        stream: [
            process.stdout,
            this.logFile
        ],
        types: ....

Error: (property) Logger.logFile: fs.WriteStream Type 'WriteStream' is missing the following properties from type 'WriteStream': clearLine, clearScreenDown, cursorTo, moveCursor, and 36 more.ts(2740)

tautf avatar Jun 02 '21 13:06 tautf

As this Plugin is not under heavy development i tried a little and made the following solution for me, for now:

Overriding the signale.d.ts types file by adding another with the following content:

import { WriteStream } from "fs";
import { SignaleOptions } from "signale";

declare namespace signale {

    interface SignaleOptionsX extends Omit<SignaleOptions, 'stream'> {
        stream?: NodeJS.Process.stdout | WriteStream | WriteStream[];
    }
}

declare const SignaleOptionsX: signale.SignaleOptionsX;

export = signale;

In my class then import { SignaleOptionsX } from '../../types/signale'; and changing SignaleOptions to SignaleOptionsX.

Now

...
stream: [
     process.stdout,
     this.logFile
]
...

Works for me again. Formatting isnt nice, but at least i dont get an error by typescript.

tautf avatar Jun 02 '21 14:06 tautf