gpt4 book ai didi

typescript - React Native 扩展 NativeModules TypeScript 类型

转载 作者:行者123 更新时间:2023-12-03 21:13:13 26 4
gpt4 key购买 nike

我有一个 native 模块,我想输入它。

这是我的模块界面的示例

export interface BBAudioPlayer {
playSound: (sound: 'click' | 'tada') => Promise<void>;
pause: () => Promise<void>;
}


这就是我使用它的方式:
NativeModules.BBAudioPlayer.playSound('tada');

如何延长 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;
}
}

enter image description here

关于typescript - React Native 扩展 NativeModules TypeScript 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62450379/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com