Skip to content

Commit ae039db

Browse files
authored
[DOC] Use CodegenTypes without deep import (#4696)
1 parent ab4f957 commit ae039db

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

docs/the-new-architecture/native-modules-custom-events.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ The first step would be to update the specs of the `NativeLocalStorage` specs to
2323
Open the `NativeLocalStorage.ts` file and update it as it follows:
2424

2525
```diff title="NativeLocalStorage.ts"
26-
import type {TurboModule} from 'react-native';
26+
+import type {TurboModule, CodegenTypes} from 'react-native';
2727
import {TurboModuleRegistry} from 'react-native';
28-
+import type {EventEmitter} from 'react-native/Libraries/Types/CodegenTypes';
2928

3029
+export type KeyValuePair = {
3130
+ key: string,
@@ -38,7 +37,7 @@ export interface Spec extends TurboModule {
3837
removeItem(key: string): void;
3938
clear(): void;
4039

41-
+ readonly onKeyAdded: EventEmitter<KeyValuePair>;
40+
+ readonly onKeyAdded: CodegenTypes.EventEmitter<KeyValuePair>;
4241
}
4342

4443
export default TurboModuleRegistry.getEnforcing<Spec>(
@@ -54,9 +53,8 @@ Open the `NativeLocalStorage.js` file and update it as it follows:
5453
```diff title="NativeLocalStorage.js"
5554

5655
// @flow
57-
import type {TurboModule} from 'react-native';
56+
+import type {TurboModule, CodegenTypes} from 'react-native';
5857
import {TurboModule, TurboModuleRegistry} from 'react-native';
59-
+import type {EventEmitter} from 'react-native/Libraries/Types/CodegenTypes';
6058

6159
+export type KeyValuePair = {
6260
+ key: string,
@@ -68,7 +66,7 @@ export interface Spec extends TurboModule {
6866
getItem(key: string): ?string;
6967
removeItem(key: string): void;
7068
clear(): void;
71-
+ onKeyAdded: EventEmitter<KeyValuePair>
69+
+ onKeyAdded: CodegenTypes.EventEmitter<KeyValuePair>
7270
}
7371
export default (TurboModuleRegistry.get<Spec>(
7472
'NativeLocalStorage'
@@ -78,7 +76,7 @@ export default (TurboModuleRegistry.get<Spec>(
7876
</TabItem>
7977
</Tabs>
8078

81-
With the `import type` statement, you are importing the `EventEmitter` type that is required to then add the `onKeyAdded` property.
79+
With the `import type` statement, you are importing the `CodegenTypes` from `react-native`, which includes the `EventEmitter` type. This allows you to define the `onKeyAdded` property using `CodegenTypes.EventEmitter<KeyValuePair>`, specifying that the event will emit a payload of type `KeyValuePair`.
8280

8381
When the event is emitted, you expect for it to receive a parameter of type `string`.
8482

website/versioned_docs/version-0.80/the-new-architecture/native-modules-custom-events.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ The first step would be to update the specs of the `NativeLocalStorage` specs to
2323
Open the `NativeLocalStorage.ts` file and update it as it follows:
2424

2525
```diff title="NativeLocalStorage.ts"
26-
import type {TurboModule} from 'react-native';
26+
+import type {TurboModule, CodegenTypes} from 'react-native';
2727
import {TurboModuleRegistry} from 'react-native';
28-
+import type {EventEmitter} from 'react-native/Libraries/Types/CodegenTypes';
2928

3029
+export type KeyValuePair = {
3130
+ key: string,
@@ -38,7 +37,7 @@ export interface Spec extends TurboModule {
3837
removeItem(key: string): void;
3938
clear(): void;
4039

41-
+ readonly onKeyAdded: EventEmitter<KeyValuePair>;
40+
+ readonly onKeyAdded: CodegenTypes.EventEmitter<KeyValuePair>;
4241
}
4342

4443
export default TurboModuleRegistry.getEnforcing<Spec>(
@@ -54,9 +53,8 @@ Open the `NativeLocalStorage.js` file and update it as it follows:
5453
```diff title="NativeLocalStorage.js"
5554

5655
// @flow
57-
import type {TurboModule} from 'react-native';
56+
+import type {TurboModule, CodegenTypes} from 'react-native';
5857
import {TurboModule, TurboModuleRegistry} from 'react-native';
59-
+import type {EventEmitter} from 'react-native/Libraries/Types/CodegenTypes';
6058

6159
+export type KeyValuePair = {
6260
+ key: string,
@@ -68,7 +66,7 @@ export interface Spec extends TurboModule {
6866
getItem(key: string): ?string;
6967
removeItem(key: string): void;
7068
clear(): void;
71-
+ onKeyAdded: EventEmitter<KeyValuePair>
69+
+ onKeyAdded: CodegenTypes.EventEmitter<KeyValuePair>
7270
}
7371
export default (TurboModuleRegistry.get<Spec>(
7472
'NativeLocalStorage'
@@ -78,7 +76,7 @@ export default (TurboModuleRegistry.get<Spec>(
7876
</TabItem>
7977
</Tabs>
8078

81-
With the `import type` statement, you are importing the `EventEmitter` type that is required to then add the `onKeyAdded` property.
79+
With the `import type` statement, you are importing the `CodegenTypes` from `react-native`, which includes the `EventEmitter` type. This allows you to define the `onKeyAdded` property using `CodegenTypes.EventEmitter<KeyValuePair>`, specifying that the event will emit a payload of type `KeyValuePair`.
8280

8381
When the event is emitted, you expect for it to receive a parameter of type `string`.
8482

0 commit comments

Comments
 (0)