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

Typings on LoggerOptions and Logger interfaces. #2021

Merged
merged 3 commits into from
Jan 13, 2022

Conversation

vanflux
Copy link
Contributor

@vanflux vanflux commented Jan 11, 2022

Some typings are missing on index.d.ts.

Missing fields:
on LoggerOptions interface:

  • handleRejections (boolean)
  • rejectionHandlers (any)

on Logger interface (suggested by DABH):

  • rejections (RejectionHandler)

Missing interfaces (suggested by DABH):

  • RejectionHandler

This commit fix it (3 commits):

Issue: #1801


One workaround for part of the problem(only for missing fields on LoggerOptions) is doing a declaration merging on winston module.

declare module 'winston' {
    export interface LoggerOptions {
        handleRejections?: boolean;
        rejectionHandlers?: any;
    }
}

export {}

The 'rejectionHandlers' field was missing on LoggerOptions interface at index.d.ts.
Issue: winstonjs#1801
A complement to rejectionHandlers commit.
@vanflux vanflux changed the title RejectionHandlers added to LoggerOptions RejectionHandlers & HandleRejections added to LoggerOptions Jan 11, 2022
@DABH
Copy link
Contributor

DABH commented Jan 13, 2022

@vanflux Can you please try to combine this with #1929 ? (E.g. cherry-pick those commits into here?) I think some combo of these two PRs will be good.

Added RejectionHandler to Logger interface,
Basically the same of PR: winstonjs#1929
Suggest by: winstonjs#2021 (comment)
@vanflux
Copy link
Contributor Author

vanflux commented Jan 13, 2022

@vanflux Can you please try to combine this with #1929 ? (E.g. cherry-pick those commits into here?) I think some combo of these two PRs will be good.

Combined

@vanflux vanflux changed the title RejectionHandlers & HandleRejections added to LoggerOptions Typings on LoggerOptions and Logger interfaces. Jan 13, 2022
@pbddog
Copy link

pbddog commented Apr 12, 2022

With Winston v3.7.1 installed, the rejections instance does not exist resulting in an unhandled exception.

const winston = require('winston');

winston.rejections.handle(
    new winston.transports.File({ filename: 'rejections.log' })
);

const p = Promise.reject(new Error('Something failed miserably!'));
p.then(()=>console.log('Done'));

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

Successfully merging this pull request may close these issues.

None yet

4 participants