Kev*_*off 5 typescript react-native
我有一个本机模块,我想输入它。
这是我的模块界面的示例
export interface BBAudioPlayer {
playSound: (sound: 'click' | 'tada') => Promise<void>;
pause: () => Promise<void>;
}
Run Code Online (Sandbox Code Playgroud)
这就是我使用它的方式:
NativeModules.BBAudioPlayer.playSound('tada');
Run Code Online (Sandbox Code Playgroud)
如何扩展NativeModules以添加我的新模块的类型?
// extendNativeModules.d.ts
// import original module declarations
import 'react-native';
export interface BBAudioPlayerInterface {
playSound: (sound: 'click' | 'tada') => Promise<void>;
pause: () => Promise<void>;
}
// and extend them!
declare module 'react-native' {
interface NativeModulesStatic {
BBAudioPlayer: BBAudioPlayerInterface;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
527 次 |
| 最近记录: |