Skip to content

Commit

Permalink
fix: update return type of function exported by default (#273) (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
tearwyx committed Nov 22, 2021
1 parent c070efb commit ddafa94
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
15 changes: 11 additions & 4 deletions index.d.ts
@@ -1,11 +1,17 @@
// Type definitions for pino-pretty 4.7
// Type definitions for pino-pretty 7.0
// Project: https://github.com/pinojs/pino-pretty#readme
// Definitions by: Adam Vigneaux <https://github.com/AdamVig>
// tearwyx <https://github.com/tearwyx>
// Minimum TypeScript Version: 3.0

/// <reference types="node" />

import { Transform } from 'stream';
import { OnUnknown } from 'pino-abstract-transport';

type LogDescriptor = Record<string, unknown>;

declare function PinoPretty(options: PrettyOptions_): PinoPretty.Prettifier;
declare function PinoPretty(options: PrettyOptions_): PinoPretty.PrettyStream;

interface PrettyOptions_ {
/**
Expand Down Expand Up @@ -121,8 +127,9 @@ interface PrettyOptions_ {
declare namespace PinoPretty {
type Prettifier = (inputData: string | object) => string;
type MessageFormatFunc = (log: LogDescriptor, messageKey: string, levelLabel: string) => string;
type PrettyOptions = PrettyOptions_
type PrettyOptions = PrettyOptions_;
type PrettyStream = Transform & OnUnknown;
}

export default PinoPretty;
export { PinoPretty, PrettyOptions_ as PrettyOptions }
export { PinoPretty, PrettyOptions_ as PrettyOptions };
25 changes: 10 additions & 15 deletions test/types/pino-pretty.test-d.ts
@@ -1,11 +1,11 @@
import prettyFactory from "../../";
import { expectType } from "tsd";

import pretty from "../../";
import PinoPretty, { PinoPretty as PinoPrettyNamed, PrettyOptions } from "../../";
import PinoPrettyDefault from "../../";
import * as PinoPrettyStar from "../../";
import PinoPrettyCjsImport = require ("../../");
import Prettifier = PinoPretty.Prettifier;
import PinoPrettyCjsImport = require("../../");
import PrettyStream = PinoPretty.PrettyStream;
const PinoPrettyCjs = require("../../");

const options: PinoPretty.PrettyOptions = {
Expand Down Expand Up @@ -52,16 +52,11 @@ const options2: PrettyOptions = {
}
};

const pretty = prettyFactory(options);
expectType<Prettifier>(pretty);

expectType<Prettifier>(PinoPrettyNamed(options));
expectType<Prettifier>(PinoPrettyDefault(options));
expectType<Prettifier>(PinoPrettyStar.PinoPretty(options));
expectType<Prettifier>(PinoPrettyStar.default(options));
expectType<Prettifier>(PinoPrettyCjsImport.PinoPretty(options));
expectType<Prettifier>(PinoPrettyCjsImport.default(options));
expectType<PrettyStream>(pretty(options));
expectType<PrettyStream>(PinoPrettyNamed(options));
expectType<PrettyStream>(PinoPrettyDefault(options));
expectType<PrettyStream>(PinoPrettyStar.PinoPretty(options));
expectType<PrettyStream>(PinoPrettyStar.default(options));
expectType<PrettyStream>(PinoPrettyCjsImport.PinoPretty(options));
expectType<PrettyStream>(PinoPrettyCjsImport.default(options));
expectType<any>(PinoPrettyCjs(options));

expectType<string>(pretty({ foo: "bar" }));
expectType<string>(pretty('dummy'));

0 comments on commit ddafa94

Please sign in to comment.