mowispace/react-native-logs

Is there a way to pass types to transport function props?

javapyscript opened this issue · 1 comments

Firstly, I would like to thank for such a nice much-needed library in the react-native world. Has been a breeze to set up and use.

The only thing I am not clear about is if there is a way to pass types to the custom transport function props. Currently, the props has the following type:
image

This means I lose the type for the log levels, the type for the msg and raw msg etc. Some transports need data filtration before sending, and doing it with anys feels a bit risky.

Is there something obvious that I am missing in the documentation?

Thank you.

Thanks!

You can define your own transportFunctionType interface:

interface transportFunctionType {
  (props: {
    msg: string; // set the type you have for msg
    rawMsg: Object; // set the type you have for rawMsg
    level: {
        severity: number;
        text: string;
    };
    extension: string;
    options: {
      filePath: string;
      fileName: string;
      colors: {
        info: string;
        warn: string;
        error: string;
      };
      //other typed options
    };
  }): void;
}

const myTransport: transportFunctionType = (props) => {
  consoleTransport(props);
  // other stuff
};