react-barcode-reader icon indicating copy to clipboard operation
react-barcode-reader copied to clipboard

Module for TypeScript

Open andresramirez82 opened this issue 4 years ago • 2 comments

module declaration for react-barcode-reader is missing. To be able to use in TYPESCRIPT

andresramirez82 avatar Apr 22 '21 12:04 andresramirez82

@andresramirez82 I needed this for my project too so I just wrote them up. Feel free to snag these and put them in a types.d.ts file

declare module 'react-barcode-reader' {
  export interface BarcodeReaderProps {
    onScan?: (barcode: string) => void;
    onError?: (barcode: string) => void;
    onReceive?: (char: string) => void;
    onKeyDetect?: (char: string) => void;
    timeBeforeScanTest?: number;
    avgTimeByChar?: number;
    minLength?: number;
    endChar?: number[];
    startChar?: number[];
    scanButtonKeyCode?: number;
    scanButtonLongPressThreshold?: number;
    onScanButtonLongPressed?: () => void;
    stopPropagation?: boolean;
    preventDefault?: boolean;
    testCode?: string;
  }

  declare class BarcodeReader extends React.Component<
    BarcodeReaderProps,
    any
  > {}

  export default BarcodeReader;
}

dstotz avatar Oct 18 '21 22:10 dstotz

Thanks for writing it up. A minor edit to the above. The onError prop is a function with two arguments. The above line:

onError?: (barcode: string) => void;

should be:

onError?: (barcode: string, message: string) => void;

jakekugel avatar Jul 03 '23 18:07 jakekugel