#How to export multiple things with types

1 messages · Page 1 of 1 (latest)

mild carbon
#

Hey, the CalendarModule example below is taken from ReactNative documentation and illustrates how type annotations can be done to a native module ('CalendarModule'). Nothing complex just defining an interface and re-exporting it with a type annotation 'attached' (as per the last line of the snippet below).
Now, I don't want to have a dedicated type per module. I'd rather have one file called eg. nativeModules.ts which would import all my native modules, define an interface for each of them and re-export with those interfaces.

I've added the 'SomeOtherModule' part but am struggling what the export section should look like to export both modules + their type definitions. Obviously, it wouldn't have the default export any more:

import { NativeModules } from 'react-native';
const { CalendarModule, SomeOtherModule } = NativeModules;
interface CalendarInterface {
  createCalendarEvent(name: string, location: string): void;
}

interface SomeOtherModuleInterface {
  init(): void;
  stop(): void;
}
export default CalendarModule as CalendarInterface;

Tried:

export { CalendarModules as CalendarInterface, SomeOtherModule as SomeOtherModuleInterface };

Thanks

ocean crystal
#

I don't know much about module types, but have you tried using something like export * from './lib/somefolder/calendar' in an other file like ìndex.ts` ?