mowispace / react-native-logs

Performance-aware simple logger for React-Native and Expo with namespaces, custom levels and custom transports (colored console, file writing, etc.)
MIT License
467 stars 33 forks source link

`any` type for dynamic log methods #41

Closed atheck closed 2 years ago

atheck commented 3 years ago

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

alessandro-bottamedi commented 2 years ago

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;
atheck commented 2 years ago

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