From c3cf6fd19be3b218797f9fb47a35dd336df4d13b Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Wed, 1 Jul 2020 01:11:10 +0200 Subject: [PATCH] fix(types): Use a union type for the type field This makes the possible values of type specifically defined, so you can handle them more safely. --- types/consola.d.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/types/consola.d.ts b/types/consola.d.ts index 093ffc65..f98f7aa8 100644 --- a/types/consola.d.ts +++ b/types/consola.d.ts @@ -13,10 +13,24 @@ export enum LogLevel { Verbose= Infinity, } +export type logType = + | 'silent' + | 'fatal' + | 'error' + | 'warn' + | 'log' + | 'info' + | 'success' + | 'debug' + | 'trace' + | 'verbose' + | 'ready' + | 'start' + export interface ConsolaLogObject { level?: LogLevel, tag?: string, - type?: string, + type?: logType, message?: string, additional?: string | string[], args?: any[], @@ -25,7 +39,7 @@ export interface ConsolaLogObject { export interface ConsolaReporterLogObject { level: LogLevel, - type: string, + type: logType, tag: string; args: any[], date: Date, @@ -33,7 +47,7 @@ export interface ConsolaReporterLogObject { type ConsolaMock = (...args: any) => void -type ConsolaMockFn = (type: string, defaults: ConsolaLogObject) => ConsolaMock +type ConsolaMockFn = (type: logType, defaults: ConsolaLogObject) => ConsolaMock export interface ConsolaReporterArgs { async: boolean, @@ -47,7 +61,7 @@ export interface ConsolaReporter { export interface ConsolaOptions { reporters?: ConsolaReporter[], - types?: { [type: string]: ConsolaLogObject }, + types?: { [type in logType]: ConsolaLogObject }, level?: LogLevel, defaults?: ConsolaLogObject, async?: boolean,