diff --git a/benchmarks/warn.js b/benchmarks/warn.js index 1437598..c327b6c 100644 --- a/benchmarks/warn.js +++ b/benchmarks/warn.js @@ -3,8 +3,16 @@ const { Suite } = require('benchmark') const { createWarning } = require('..') -const err1 = createWarning('FastifyWarning', 'FST_ERROR_CODE_1', 'message') -const err2 = createWarning('FastifyWarning', 'FST_ERROR_CODE_2', 'message') +const err1 = createWarning({ + name: 'FastifyWarning', + code: 'FST_ERROR_CODE_1', + message: 'message' +}) +const err2 = createWarning({ + name: 'FastifyWarning', + code: 'FST_ERROR_CODE_2', + message: 'message' +}) new Suite() .add('warn', function () { diff --git a/types/index.d.ts b/types/index.d.ts index 8cfe8f7..0165c33 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -9,17 +9,26 @@ declare namespace processWarning { format(a?: any, b?: any, c?: any): string; } + export type WarningOptions = { + name: string; + code: string; + message: string; + unlimited?: boolean; + } + + export type DeprecationOptions = Omit + export type ProcessWarningOptions = { unlimited?: boolean; } export type ProcessWarning = { - createWarning(name: string, code: string, message: string, opts?: ProcessWarningOptions): WarningItem; - createDeprecation(code: string, message: string, opts?: ProcessWarningOptions): WarningItem; + createWarning(params: WarningOptions): WarningItem; + createDeprecation(params: DeprecationOptions): WarningItem; } - export function createDeprecation(code: string, message: string, opts?: ProcessWarningOptions): WarningItem; - export function createWarning(name: string, code: string, message: string, opts?: ProcessWarningOptions): WarningItem; + export function createWarning(params: WarningOptions): WarningItem; + export function createDeprecation(params: DeprecationOptions): WarningItem; const processWarning: ProcessWarning; export { processWarning as default }; diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 747e5a5..f5e83bd 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -1,7 +1,11 @@ import { expectType } from 'tsd' import { createWarning, createDeprecation } from '..' -const WarnInstance = createWarning('FastifyWarning', 'CODE', 'message') +const WarnInstance = createWarning({ + name: 'FastifyWarning', + code: 'CODE', + message: 'message' +}) expectType(WarnInstance.code) expectType(WarnInstance.message) @@ -13,10 +17,18 @@ expectType(WarnInstance.emit()) expectType(WarnInstance.emit('foo')) expectType(WarnInstance.emit('foo', 'bar')) -const buildWarnUnlimited = createWarning('FastifyWarning', 'CODE', 'message', { unlimited: true }) +const buildWarnUnlimited = createWarning({ + name: 'FastifyWarning', + code: 'CODE', + message: 'message', + unlimited: true +}) expectType(buildWarnUnlimited.unlimited) -const DeprecationInstance = createDeprecation('CODE', 'message') +const DeprecationInstance = createDeprecation({ + code: 'CODE', + message: 'message' +}) expectType(DeprecationInstance.code) DeprecationInstance.emit()