From be58e6ad162e1cef0901772266090518b09ee779 Mon Sep 17 00:00:00 2001 From: Sahin Vardar Date: Tue, 29 Aug 2017 20:18:46 +0200 Subject: [PATCH] Fixes #18734 * Altered typing of NativeModulesStatic to enable NativeModule modules of type any and typed native modules at the same time. * Added test case for typed and untyped native modules. --- types/react-native/index.d.ts | 7 +++++-- types/react-native/test/index.tsx | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 6346297446..074c90265d 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -9126,9 +9126,12 @@ export var NativeEventEmitter: NativeEventEmitter export var NativeAppEventEmitter: RCTNativeAppEventEmitter /** - * Empty interface which can be augmented by other type definitions for the NativeModules var below. + * Interface for NativeModules which allows to augment NativeModules with type informations. + * See react-native-sensor-manager for example. */ -interface NativeModulesStatic {} +interface NativeModulesStatic { + [name: string]: any; +} /** * Native Modules written in ObjectiveC/Swift/Java exposed via the RCTBridge diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index 36e87d6aa9..57c8bb106a 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -39,8 +39,24 @@ import { ScrollViewProps, RefreshControl, TabBarIOS, + NativeModules } from 'react-native'; +declare module 'react-native' { + interface NativeTypedModule { + someFunction(): void; + someProperty: string; + } + interface NativeModulesStatic { + NativeTypedModule: NativeTypedModule + } +} + +NativeModules.NativeUntypedModule; + +NativeModules.NativeTypedModule.someFunction(); +NativeModules.NativeTypedModule.someProperty = ""; + function testDimensions() { const { width,