UNPKG

2.36 kBTypeScriptView Raw
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9
10declare module 'react-native/Libraries/Utilities/codegenNativeCommands' {
11 export interface Options<T extends string> {
12 readonly supportedCommands: ReadonlyArray<T>;
13 }
14
15 function codegenNativeCommands<T extends object>(
16 options: Options<keyof T extends string ? keyof T : never>,
17 ): T;
18
19 export default codegenNativeCommands;
20}
21
22declare module 'react-native/Libraries/Utilities/codegenNativeComponent' {
23 import type {HostComponent} from 'react-native';
24
25 export interface Options {
26 readonly interfaceOnly?: boolean | undefined;
27 readonly paperComponentName?: string | undefined;
28 readonly paperComponentNameDeprecated?: string | undefined;
29 readonly excludedPlatforms?: ReadonlyArray<'iOS' | 'android'> | undefined;
30 }
31
32 export type NativeComponentType<T> = HostComponent<T>;
33
34 function codegenNativeComponent<Props extends object>(
35 componentName: string,
36 options?: Options,
37 ): NativeComponentType<Props>;
38
39 export default codegenNativeComponent;
40}
41
42declare module 'react-native/Libraries/Types/CodegenTypes' {
43 import type {NativeSyntheticEvent} from 'react-native';
44
45 // Event types
46 // We're not using the PaperName, it is only used to codegen view config settings
47
48 export type BubblingEventHandler<
49 T,
50 PaperName extends string | never = never,
51 > = (event: NativeSyntheticEvent<T>) => void | Promise<void>;
52 export type DirectEventHandler<
53 T,
54 PaperName extends string | never = never,
55 > = (event: NativeSyntheticEvent<T>) => void | Promise<void>;
56
57 // Prop types
58 export type Double = number;
59 export type Float = number;
60 export type Int32 = number;
61 export type UnsafeObject = object;
62
63 type DefaultTypes = number | boolean | string | ReadonlyArray<string>;
64 // Default handling, ignore the unused value
65 // we're only using it for type checking
66 //
67 // TODO: (rickhanlonii) T44881457 If a default is provided, it should always be optional
68 // but that is currently not supported in the codegen since we require a default
69
70 export type WithDefault<
71 Type extends DefaultTypes,
72 Value extends Type | string | undefined | null,
73 > = Type | undefined | null;
74}