forked from pinojs/pino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pino-type-only.test-d.ts
28 lines (22 loc) 路 992 Bytes
/
pino-type-only.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { expectAssignable, expectType } from "tsd";
import pino from "../../";
import type {LevelWithSilent, Logger, LogFn, P, DestinationStreamWithMetadata } from "../../pino";
// NB: can also use `import * as pino`, but that form is callable as `pino()`
// under `esModuleInterop: false` or `pino.default()` under `esModuleInterop: true`.
const log = pino();
expectType<Logger>(log);
expectType<LogFn>(log.info);
expectType<P.Logger>(log);
expectType<P.LogFn>(log.info);
const level: LevelWithSilent = 'silent';
expectAssignable<P.LevelWithSilent>(level);
function createStream(): DestinationStreamWithMetadata {
return { write() {} };
}
const stream = createStream();
// Argh. TypeScript doesn't seem to narrow unless we assign the symbol like so, and tsd seems to
// break without annotating the type explicitly
const needsMetadata: typeof pino.symbols.needsMetadataGsym = pino.symbols.needsMetadataGsym;
if (stream[needsMetadata]) {
expectType<number>(stream.lastLevel);
}