Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6211

Calling native function from TypeScript in react-native

$
0
0

Lately I needed a simple function to interact with the native code, but I decided not to build a package, because it wouldn't be very useful. I created the java files exactly as if they were from a plugin and registered it in MainApplication.

I'm using typescript so now I'm struggling with the rn to java interaction. I tried with a js file as follows:

import NativeModules from 'react-native';
const AndroidService = NativeModules;
export default { AndroidService }

But then I have to define types (message from vs code):

Property 'play' does not exist on type '{ AndroidService: typeof import("/home/karol/Git/TailosiveHub-react/node_modules/@types/react-native/index"); }'.

I tried creating a index.d.ts file in the root of the project, but that doesn't work.

How do I define types for a native module in typescript?


Viewing all articles
Browse latest Browse all 6211

Trending Articles