Skip to content

Commit d2f6c64

Browse files
authored
fix: allow object type in %s placeholder (#2277)
* fix: allow object type in %s placeholder * fixup Signed-off-by: Matteo Collina <[email protected]> --------- Signed-off-by: Matteo Collina <[email protected]>
1 parent 8807cc2 commit d2f6c64

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

pino.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ declare namespace pino {
326326
type PlaceholderTypeMapping<T extends PlaceholderSpecifier> = T extends 'd'
327327
? number
328328
: T extends 's'
329-
? string | number | boolean | bigint | null | undefined | symbol
329+
? unknown
330330
: T extends 'j' | 'o' | 'O'
331331
? object
332332
: never;
@@ -878,4 +878,4 @@ declare function pino<CustomLevels extends string = never, UseOnlyCustomLevels e
878878
*/
879879
declare function pino<CustomLevels extends string = never, UseOnlyCustomLevels extends boolean = boolean>(options: pino.LoggerOptions<CustomLevels, UseOnlyCustomLevels>, stream?: pino.DestinationStream | undefined): pino.Logger<CustomLevels, UseOnlyCustomLevels>;
880880

881-
export = pino;
881+
export = pino;

test/types/pino.test-d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ info({ a: 1, b: '2' }, 'hello world with %s', 'extra data');
7171
// Extra message after placeholder
7272
expectError(info({ a: 1, b: '2' }, 'hello world with %d', 2, 'extra' ));
7373

74-
// metadata with messages type errors
75-
expectError(info({ a: 1, b: '2' }, 'hello world with %s', {}));
74+
// metadata with messages type passes, because of custom toString method
75+
// We can't detect if the object has a custom toString method that returns a string
76+
info({ a: 1, b: '2' }, 'hello world with %s', {});
7677

7778
// metadata after message
7879
expectError(info('message', { a: 1, b: '2' }));

0 commit comments

Comments
 (0)