From cb3198d5998bdb11ef05dfa5ef98d5c5fa873089 Mon Sep 17 00:00:00 2001 From: Thomas Truong Date: Fri, 23 Oct 2020 10:47:28 +0100 Subject: [PATCH] feat(types): adding logger type for logger plugin (#1853) `createLogger` takes in logger option which by default is console but can be overridden with own logger. Here we addd `Logger` interface for `logger` options params which expects log method to be implemented. Co-authored-by: Thomas Truong --- types/logger.d.ts | 6 ++++++ types/test/index.ts | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/types/logger.d.ts b/types/logger.d.ts index 873af7f0d..b6b160063 100644 --- a/types/logger.d.ts +++ b/types/logger.d.ts @@ -1,5 +1,10 @@ import { Payload, Plugin } from "./index"; +interface Logger extends Partial> { + log(message: string, colour: string, action: any): void; + log(message: string): void; +} + export interface LoggerOption { collapsed?: boolean; filter?:

(mutation: P, stateBefore: S, stateAfter: S) => boolean; @@ -9,6 +14,7 @@ export interface LoggerOption { actionTransformer?:

(action: P) => any; logMutations?: boolean; logActions?: boolean; + logger?: Logger; } export default function createLogger(option?: LoggerOption): Plugin; diff --git a/types/test/index.ts b/types/test/index.ts index c801264a8..32d5ec2c6 100644 --- a/types/test/index.ts +++ b/types/test/index.ts @@ -437,10 +437,17 @@ namespace Plugins { }); } + class MyLogger { + log(message: string) { + console.log(message); + } + } + const logger = Vuex.createLogger<{ value: number }>({ collapsed: true, transformer: state => state.value, - mutationTransformer: (mutation: { type: string }) => mutation.type + mutationTransformer: (mutation: { type: string }) => mutation.type, + logger: new MyLogger() }); const store = new Vuex.Store<{ value: number }>({