0
# TypeScript Types
1
2
Comprehensive type system covering CLI configuration, commands, platform definitions, and development tool integration. All types are exported from `@react-native-community/cli-types`.
3
4
## Capabilities
5
6
### Core Configuration Types
7
8
Primary interfaces for React Native CLI configuration and project settings.
9
10
```typescript { .api }
11
/**
12
* Main CLI configuration containing project settings, platforms, and commands
13
*/
14
interface Config {
15
/** Project root directory path */
16
root: string;
17
/** Path to React Native installation */
18
reactNativePath: string;
19
/** Platform-specific configurations (Android, iOS, etc.) */
20
platforms: Record<string, PlatformConfig<any, any, any, any>>;
21
/** Available CLI commands */
22
commands: Command[];
23
/** Project dependencies with linking configuration */
24
dependencies: Record<string, DependencyConfig>;
25
/** Asset directories to include in builds */
26
assets: string[];
27
/** Haste module system configuration */
28
haste: {
29
platforms: string[];
30
providesModuleNodeModules: string[];
31
};
32
/** Metro resolver configuration */
33
resolver: {
34
resolverMainFields: string[];
35
platforms: string[];
36
};
37
}
38
39
/**
40
* User-provided configuration subset that can be specified in react-native.config.js
41
*/
42
interface UserConfig {
43
dependencies?: Record<string, UserDependencyConfig>;
44
assets?: string[];
45
platforms?: Record<string, Partial<PlatformConfig<any, any, any, any>>>;
46
commands?: Command[];
47
}
48
```
49
50
### Command System Types
51
52
Interfaces and types for the CLI command system with conditional typing for attached and detached commands.
53
54
```typescript { .api }
55
/**
56
* Generic command interface with conditional typing for attached/detached commands
57
*/
58
interface Command<IsDetached extends boolean = boolean> {
59
/** Command name as used in CLI */
60
name: string;
61
/** Optional command description */
62
description?: string;
63
/** Command implementation function */
64
func: IsDetached extends true ? DetachedCommandFunction : CommandFunction;
65
/** Whether command works without project configuration */
66
detached?: IsDetached;
67
/** Command-line options */
68
options?: CommandOption[];
69
/** Usage examples */
70
examples?: Array<{desc: string; cmd: string}>;
71
}
72
73
/**
74
* Type alias for commands that work without project configuration
75
*/
76
type DetachedCommand = Command<true>;
77
78
/**
79
* Function signature for attached commands (require project configuration)
80
*/
81
type CommandFunction<Args = Object> = (
82
argv: Array<string>,
83
ctx: Config,
84
args: Args
85
) => Promise<void> | void;
86
87
/**
88
* Function signature for detached commands (work standalone)
89
*/
90
type DetachedCommandFunction<Args = Object> = (
91
argv: string[],
92
args: Args,
93
ctx: Config
94
) => Promise<void> | void;
95
96
/**
97
* Command option configuration
98
*/
99
interface CommandOption<T = OptionValue> {
100
/** Option name/flags (e.g., '--verbose', '-v --verbose') */
101
name: string;
102
/** Option description for help text */
103
description?: string;
104
/** Optional parsing function to transform the option value */
105
parse?: (value: string) => T;
106
/** Default value or function that returns default value */
107
default?: T | ((config?: Config) => T);
108
}
109
110
/**
111
* Valid command option value types
112
*/
113
type OptionValue = string | boolean | number;
114
```
115
116
### Platform Configuration Types
117
118
Generic platform configuration system supporting Android, iOS, and out-of-tree platforms.
119
120
```typescript { .api }
121
/**
122
* Generic platform configuration structure
123
*/
124
interface PlatformConfig<
125
ProjectConfig,
126
ProjectParams,
127
DependencyConfig,
128
DependencyParams
129
> {
130
/** Platform name identifier */
131
npmPackageName: string;
132
/** Function to find project configuration */
133
projectConfig: (
134
projectRoot: string,
135
projectParams: ProjectParams | void
136
) => ProjectConfig | void;
137
/** Function to find dependency configuration */
138
dependencyConfig: (
139
dependency: string,
140
params: DependencyParams
141
) => DependencyConfig | void;
142
}
143
144
/**
145
* Project configuration with Android and iOS settings
146
*/
147
interface ProjectConfig {
148
android?: AndroidProjectConfig;
149
ios?: IOSProjectConfig;
150
}
151
152
/**
153
* Dependency configuration for native linking
154
*/
155
interface DependencyConfig {
156
name: string;
157
root: string;
158
platforms: {
159
android?: AndroidDependencyConfig;
160
ios?: IOSDependencyConfig;
161
[key: string]: any;
162
};
163
}
164
```
165
166
### Android Platform Types
167
168
Android-specific configuration types for project setup and dependency linking.
169
170
```typescript { .api }
171
/**
172
* Android project configuration
173
*/
174
interface AndroidProjectConfig {
175
/** Source directory path */
176
sourceDir: string;
177
/** App source directory path */
178
appName: string;
179
/** Android package name */
180
packageName: string;
181
/** Path to AndroidManifest.xml */
182
manifestPath: string;
183
/** Build.gradle file path */
184
buildGradlePath: string;
185
/** Settings.gradle file path */
186
settingsGradlePath: string;
187
/** MainActivity.java file path */
188
mainActivityPath: string;
189
/** Strings.xml file path */
190
stringsPath: string;
191
}
192
193
/**
194
* Parameters for Android project configuration
195
*/
196
interface AndroidProjectParams {
197
sourceDir?: string;
198
appName?: string;
199
packageName?: string;
200
manifestPath?: string;
201
buildGradlePath?: string;
202
settingsGradlePath?: string;
203
mainActivityPath?: string;
204
stringsPath?: string;
205
}
206
207
/**
208
* Android dependency configuration for native linking
209
*/
210
interface AndroidDependencyConfig {
211
/** Source directory containing native code */
212
sourceDir: string;
213
/** Package name for the dependency */
214
packageName: string;
215
/** Gradle dependency statement */
216
dependencyConfiguration?: string;
217
/** Path to build.gradle */
218
buildGradlePath?: string;
219
/** Library name */
220
libraryName?: string;
221
/** Component descriptors for linking */
222
componentDescriptors?: string[];
223
/** AndroidManifest.xml path */
224
androidMkPath?: string;
225
}
226
227
/**
228
* Parameters for Android dependency configuration
229
*/
230
interface AndroidDependencyParams {
231
sourceDir?: string;
232
packageName?: string;
233
dependencyConfiguration?: string;
234
buildGradlePath?: string;
235
libraryName?: string;
236
componentDescriptors?: string[];
237
androidMkPath?: string;
238
}
239
```
240
241
### iOS Platform Types
242
243
iOS-specific configuration types for Xcode project setup and dependency linking.
244
245
```typescript { .api }
246
/**
247
* iOS project configuration
248
*/
249
interface IOSProjectConfig {
250
/** Xcode project information */
251
xcodeProject: IOSProjectInfo;
252
/** CocoaPods Podfile path */
253
podfile: string;
254
/** Podspec file path */
255
podspecPath: string;
256
/** Library folder for static libraries */
257
libraryFolder: string;
258
/** Shared libraries configuration */
259
sharedLibraries: string[];
260
/** Podfile template path */
261
plist: string[];
262
}
263
264
/**
265
* Parameters for iOS project configuration
266
*/
267
interface IOSProjectParams {
268
xcodeProject?: Partial<IOSProjectInfo>;
269
podfile?: string;
270
podspecPath?: string;
271
libraryFolder?: string;
272
sharedLibraries?: string[];
273
plist?: string[];
274
}
275
276
/**
277
* iOS dependency configuration for native linking
278
*/
279
interface IOSDependencyConfig {
280
/** Podspec file path */
281
podspecPath: string;
282
/** Library name */
283
libraryName: string;
284
/** Xcode project path */
285
projectPath: string;
286
/** Shared libraries */
287
sharedLibraries: string[];
288
/** Header search paths */
289
headerSearchPaths: string[];
290
/** Script phases for build process */
291
scriptPhases: IOSScriptPhase[];
292
}
293
294
/**
295
* Parameters for iOS dependency configuration
296
*/
297
interface IOSDependencyParams {
298
podspecPath?: string;
299
libraryName?: string;
300
projectPath?: string;
301
sharedLibraries?: string[];
302
headerSearchPaths?: string[];
303
scriptPhases?: IOSScriptPhase[];
304
}
305
306
/**
307
* iOS project information
308
*/
309
interface IOSProjectInfo {
310
/** Project name */
311
name: string;
312
/** Path to .xcodeproj or .xcworkspace */
313
path: string;
314
/** Whether it's an Xcode workspace */
315
isWorkspace: boolean;
316
}
317
318
/**
319
* CocoaPods script phase configuration
320
*/
321
interface IOSScriptPhase {
322
/** Script phase name */
323
name: string;
324
/** Script path or command */
325
path: string;
326
/** Execution position in build phases */
327
execution_position?: 'before_compile' | 'after_compile' | 'before_headers' | 'after_headers';
328
/** Input file paths */
329
input_files?: string[];
330
/** Output file paths */
331
output_files?: string[];
332
}
333
```
334
335
### Utility Types
336
337
Additional utility types for CLI functionality and user configuration.
338
339
```typescript { .api }
340
/**
341
* User-provided dependency configuration
342
*/
343
interface UserDependencyConfig {
344
/** Platforms to enable for this dependency */
345
platforms?: {
346
android?: Partial<AndroidDependencyConfig> | null;
347
ios?: Partial<IOSDependencyConfig> | null;
348
};
349
/** Asset directories */
350
assets?: string[];
351
/** Build hooks */
352
hooks?: {
353
prelink?: string;
354
postlink?: string;
355
preunlink?: string;
356
postunlink?: string;
357
};
358
}
359
360
/**
361
* Prompt type for interactive CLI operations
362
*/
363
type Prompt = any;
364
```
365
366
## Usage Examples
367
368
### Type Usage in Commands
369
370
```typescript
371
import type { Config, Command, DetachedCommand } from "@react-native-community/cli-types";
372
373
// Define a project command
374
const myProjectCommand: Command<false> = {
375
name: "my-command",
376
description: "Custom project command",
377
func: async (argv: string[], config: Config, options: any) => {
378
console.log("Project root:", config.root);
379
console.log("Available platforms:", Object.keys(config.platforms));
380
},
381
options: [
382
{
383
name: "--output <path>",
384
description: "Output directory",
385
default: "./output"
386
}
387
]
388
};
389
390
// Define a detached command
391
const myDetachedCommand: DetachedCommand = {
392
name: "my-init",
393
description: "Custom init command",
394
detached: true,
395
func: async (argv: string[], options: any, config?: Config) => {
396
console.log("Running detached command");
397
if (config) {
398
console.log("Found project configuration");
399
}
400
}
401
};
402
```
403
404
### Type Usage in Configuration
405
406
```typescript
407
import type { UserConfig, AndroidProjectParams, IOSProjectParams } from "@react-native-community/cli-types";
408
409
// Custom react-native.config.js
410
const config: UserConfig = {
411
dependencies: {
412
"my-native-library": {
413
platforms: {
414
android: {
415
sourceDir: "android/src/main/java",
416
packageName: "com.example.mylibrary"
417
},
418
ios: {
419
podspecPath: "ios/MyLibrary.podspec"
420
}
421
}
422
}
423
},
424
assets: ["./src/assets/fonts/"]
425
};
426
```