UNPKG

brick-module

Version:

Better React Native native module development

55 lines (53 loc) 1.71 kB
import { TurboModule } from "react-native"; //#region src/BrickModule.d.ts /** * Base interface that all Brick module specs must extend */ interface BrickModuleInterface extends TurboModule { readonly moduleName: string; } /** * Type alias for module specifications * Use this as the base interface when defining your module specs * @example * export interface MyModuleSpec extends BrickModuleSpec { * readonly moduleName: "MyModule"; * readonly supportedEvents: ["eventA", "eventB"]; * myMethod(param: string): Promise<string>; * } */ type BrickModuleSpec = BrickModuleInterface; /** * Enhanced typed module interface with event listeners */ type BrickModuleWithEvents<T extends BrickModuleInterface> = T; /** * Gets a typed module instance by name with explicit type parameter * @param moduleName - The exact name of the module as defined in its spec * @returns Typed module interface with all methods, constants, and event listeners */ declare function get<T extends BrickModuleInterface>(moduleName: string): BrickModuleWithEvents<T>; /** * Gets list of all registered modules * @returns Promise resolving to array of module names */ declare function getRegisteredModules(): string[]; /** * Clears the module cache (useful for testing or hot reloading) * @internal */ declare function clearCache(): void; /** * Main Brick Module API object * Provides type-safe access to native modules */ declare const BrickModule: { readonly get: typeof get; readonly getRegisteredModules: typeof getRegisteredModules; readonly clearCache: typeof clearCache; }; /** * Default export for convenience */ //#endregion export { BrickModule, BrickModuleInterface, BrickModuleSpec };