winston-graylog2 icon indicating copy to clipboard operation
winston-graylog2 copied to clipboard

Update TypeScript typings for the latest (v2.0.0) version

Open schfkt opened this issue 6 years ago • 6 comments

https://github.com/namshi/winston-graylog2/releases/tag/v2.0.0 contains breaking changes that must be reflected in TS typings as well.

schfkt avatar Jan 28 '19 14:01 schfkt

Typescript types are still broken (by this very change). Hopefully we can get a PR in, this is blocking us.

popbee avatar Mar 21 '19 14:03 popbee

Feel free to send a pr :)

odino avatar Mar 22 '19 01:03 odino

@popbee

Typescript types are still broken (by this very change). Hopefully we can get a PR in, this is blocking us.

What error do you get? Please provide more info, so I'll be able to fix it. Ideally, a TS code sample, that doesn't compile.

schfkt avatar Mar 22 '19 12:03 schfkt

Thank you for considering this issue.

As soon as we can, we'll try to get the exact error, something to repro or even directly a PR. Essentially we are just setting it up normally with Winston. There isn't much in there and TSC just fails doing type checking, pointing to this library installed in node_module/ (not pointing to our code). (I haven't tried, but potentially just having const winstonGraylog2 = require('winston-graylog2'); is enough to trig the issue. I could be wrong thought.

We are compiling with the "real" Typescript (not Babel) and the Typescript version is 3.0.1.

popbee avatar Mar 22 '19 18:03 popbee

@popbee sorry for a late reply, missed your message somehow. The following code compiles fine for me:

import * as winston from "winston";
import * as WinstonGraylog2 from "winston-graylog2";

const options = {
  graylog: {
    servers: [
      {
        host: "127.0.0.1",
        port: 12201,
      },
    ],
  },
};

const graylog2Transport = new WinstonGraylog2(options);
const logger = winston.createLogger({
  exitOnError: true,
  transports: [graylog2Transport]
});

logger.info("Hello there!", {some: 42, doge: 12});

And this one:

const winston = require("winston");
const WinstonGraylog2 = require("winston-graylog2");

const options = {
  graylog: {
    servers: [
      {
        host: "127.0.0.1",
        port: 12201,
      },
    ],
  },
};

const graylog2Transport = new WinstonGraylog2(options);
const logger = winston.createLogger({
  exitOnError: true,
  transports: [graylog2Transport]
});

logger.info("Hello there!", {some: 42, doge: 12});

Although, I personally don't use requires with TypeScript. Here's the tsconfig.json I used:

{
  "compilerOptions": {
    "outDir": "build",
    "module": "commonjs",
    "target": "ES2017"
  },
  "include": [
    "src"
  ]
}

schfkt avatar Apr 05 '19 15:04 schfkt

Hello @schfkt, your example code above does trigger Typescript errors for me using latest Winston 3.2.1.

Argument of type '{ exitOnError: true; transports: Graylog2Transport[]; }' is not assignable to parameter of type 'LoggerOptions'.
  Types of property 'transports' are incompatible.
    Type 'Graylog2Transport[]' is not assignable to type 'TransportStream | TransportStream[] | undefined'.
      Type 'Graylog2Transport[]' is not assignable to type 'TransportStream[]'.
        Type 'Graylog2Transport' is missing the following properties from type 'TransportStream': writable, writableHighWaterMark, writableLength, _write, and 24 more.ts(2345) 

Also, I wondered if your library works out of the box with Graylog 3.0.

Best -act

actraiser avatar May 24 '19 08:05 actraiser