mowispace/react-native-logs

`any` type for dynamic log methods

Closed this issue · 2 comments

Is it possible to not use any for dynamic log methods in class logTyped? Maybe these methods can be typed like this:

(...args: unknown []) => void

Creating a standard type for the whole logger class without knowing the log level names first is complex.
However if you want to have a better typed log function you could create your own type and assign it to the logger object:

type myLoggerType = {
  debug: (...args: unknown[]) => void;
  info: (...args: unknown[]) => void;
  warn: (...args: unknown[]) => void;
  error: (...args: unknown[]) => void;
};

const LOG = logger.createLogger(loggerConfig) as any as myLoggerType;

Thanks for your reply @alessandro-bottamedi. This is a good solution.