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

WriteStream object is not accepted in stream array #117

Open
tautf opened this issue Jun 2, 2021 · 1 comment
Open

WriteStream object is not accepted in stream array #117

tautf opened this issue Jun 2, 2021 · 1 comment

Comments

@tautf
Copy link

tautf commented Jun 2, 2021

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
Copy link
Author

tautf commented Jun 2, 2021

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.

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

No branches or pull requests

1 participant