Skip to content

Commit 791adbe

Browse files
authored
fix: allow passing string, number, null for %o placeholder (#2372)
* fix: allow passing string, number, null for %o placeholder * update tests
1 parent 851a43f commit 791adbe

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

pino.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ declare namespace pino {
326326
: T extends 's'
327327
? unknown
328328
: T extends 'j' | 'o' | 'O'
329-
? object
329+
? {} | null
330330
: never;
331331

332332
type ParseLogFnArgs<

test/types/pino.test-d.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,19 @@ info('All primitive types %s %s %s %s %s %s %s', 'string', 123, true, BigInt(123
5454
declare const errorOrString: string | Error;
5555
info(errorOrString)
5656

57+
// %o placeholder supports primitives too (except undefined)
58+
info('Boolean %o', true);
59+
info('Boolean %o', false);
60+
info('Number %o', 123);
61+
info('Number %o', 3.14);
62+
info('BigInt %o', BigInt(123));
63+
info('Null %o', null);
64+
info('Symbol %o', Symbol('test'));
65+
info('String %o', 'hello');
66+
5767
// placeholder messages type errors
5868
expectError(info('The answer is %d', 'not a number'));
59-
expectError(info('The object is %o', 'not an object'));
60-
expectError(info('The object is %j', 'not a JSON'));
61-
expectError(info('The object is %O', 'not an object'));
62-
expectError(info('The answer is %d and the question is %s with %o', 42, { incorrect: 'order' }, 'unknown'));
69+
expectError(info('The answer is %d and the question is %s with %o', 'unknown', { incorrect: 'order' }, 42));
6370
expectError(info('Extra message %s', 'after placeholder', 'not allowed'));
6471

6572
// object types with messages

0 commit comments

Comments
 (0)