My goal is to write everything in interface, TypeScript. It's for React Native.
This is the function I am unable to put into an interface. The current solution is to put it outside the interface but the import would be ugly e.g import AudioRecorderModule, { addAudioRecorderEventListener } from '...'
export const addAudioRecorderEventListener = ( listener: (data: number[]) => void,) => eventEmitter.addListener('read', listener);
AudioRecorder.module.ts
import {NativeEventEmitter, NativeModules} from 'react-native';import AudioRecorderInterface from './AudioRecorder.d';const {AudioRecorderModule} = NativeModules;const eventEmitter = new NativeEventEmitter(AudioRecorderModule);export const addAudioRecorderEventListener = ( listener: (data: number[]) => void,) => eventEmitter.addListener('read', listener);export default AudioRecorderModule as AudioRecorderInterface;
AudioRecorder.d.ts
export default interface AudioRecorderInterface { startAudioRecordingAsync(): Promise<null>; stopAudioRecordingAsync(): Promise<null>;}