Skip to content

Commit de05579

Browse files
authored
Label dictionary keys in react-native (#59818)
Summary: Labels unlabeled dictionary keys: `{[string]: T}` becomes `{[key: string]: T}`. In TypeScript, `{[string]: T}` is a computed property, not an index signature, so this prepares the code for `experimental.require_dictionary_key_label`, which requires the label. The label is documentation only and does not change any type. Generated by the `flow/nameIndexerKeys` codemod, run only on the keys that the flag reports, so computed keys like `{['a']: T}` are left alone. Keys inside comment types, and files whose formatting the codemod's printer would change, were labeled with a plain text insertion instead. Changelog: [Internal] Differential Revision: D130071787 Pull Request resolved: #59818
1 parent 53f48ad commit de05579

145 files changed

Lines changed: 507 additions & 478 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/asset-utils/src/AndroidPathUtils.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type PackagerAsset = Readonly<{
2020
}>;
2121
*/
2222

23-
const androidScaleSuffix /*: {[string]: string} */ = {
23+
const androidScaleSuffix /*: {[key: string]: string} */ = {
2424
'0.75': 'ldpi',
2525
'1': 'mdpi',
2626
'1.5': 'hdpi',

‎packages/debugger-shell/src/electron/SettingsStore.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ export default class SettingsStore {
9191
}
9292
}
9393

94-
get store(): {[string]: unknown} {
94+
get store(): {[key: string]: unknown} {
9595
try {
9696
const data = fs.readFileSync(this.path, 'utf8');
9797
const deserializedData = this._deserialize(data);
9898
return {
99-
...(deserializedData as any as {[string]: unknown}),
99+
...(deserializedData as any as {[key: string]: unknown}),
100100
};
101101
} catch (error) {
102102
if (error?.code === 'ENOENT') {

‎packages/dev-middleware/src/__tests__/InspectorDebuggerUtils.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class DebuggerAgent {
2525
constructor(
2626
url: string,
2727
signal?: AbortSignal,
28-
headers?: ?{[string]: unknown},
28+
headers?: ?{[key: string]: unknown},
2929
) {
3030
const ws = new WebSocket(url, {
3131
// The mock server uses a self-signed certificate.
@@ -122,7 +122,7 @@ export class DebuggerMock extends DebuggerAgent {
122122
export async function createDebuggerMock(
123123
url: string,
124124
signal: AbortSignal,
125-
headers?: ?{[string]: unknown},
125+
headers?: ?{[key: string]: unknown},
126126
): Promise<DebuggerMock> {
127127
const debuggerMock = new DebuggerMock(url, signal, headers);
128128
await debuggerMock.ready();

‎packages/dev-middleware/src/__tests__/InspectorProtocolUtils.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export async function createAndConnectTarget(
126126
deviceId = null,
127127
deviceHostHeader = null,
128128
}: Readonly<{
129-
debuggerHeaders?: ?{[string]: unknown},
129+
debuggerHeaders?: ?{[key: string]: unknown},
130130
debuggerOriginHeader?: ?string,
131131
deviceId?: ?string,
132132
deviceHostHeader?: ?string,

‎packages/dev-middleware/src/inspector-proxy/CdpDebugLogging.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function getCDPLogPrefix(destination: CDPMessageDestination): string {
3939

4040
export default class CdpDebugLogging {
4141
#cdpMessagesLoggingBatchingFn: {
42-
[CDPMessageDestination]: (message: string) => void,
42+
[key: CDPMessageDestination]: (message: string) => void,
4343
} = {
4444
DebuggerToProxy: () => {},
4545
ProxyToDebugger: () => {},
@@ -55,7 +55,7 @@ export default class CdpDebugLogging {
5555

5656
#initializeThrottledCDPMessageLogging(): void {
5757
const batchingCounters: {
58-
[CDPMessageDestination]: {count: number, size: number},
58+
[key: CDPMessageDestination]: {count: number, size: number},
5959
} = {
6060
DebuggerToProxy: {count: 0, size: 0},
6161
ProxyToDebugger: {count: 0, size: 0},

‎packages/dev-middleware/src/inspector-proxy/types.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export type JSONSerializable =
158158
| string
159159
| null
160160
| ReadonlyArray<JSONSerializable>
161-
| {readonly [string]: JSONSerializable};
161+
| {readonly [key: string]: JSONSerializable};
162162

163163
export type DeepReadOnly<T> =
164164
T extends ReadonlyArray<infer V>

‎packages/jest-preset/jest/__tests__/preset-react-native-dep-test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ test(`isolated preset loads when the consumer provides react-native (${RN_ISSUE}
7676
// Strip resolution-affecting env so the child is genuinely isolated:
7777
// inherited lookup paths can otherwise make the copy resolve more
7878
// than the directory layout alone provides.
79-
const childEnv: {[string]: string} = {};
79+
const childEnv: {[key: string]: string} = {};
8080
for (const key of Object.keys(process.env)) {
8181
if (key === 'NODE_PATH' || key === 'NODE_OPTIONS') {
8282
continue;

‎packages/react-native-babel-preset/src/__tests__/transform-runtime-caller-test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const MOCK_FILENAME = '/absolute/path/to/input.js';
1818

1919
function transformWithCaller(
2020
code: string,
21-
options: {[string]: unknown},
21+
options: {[key: string]: unknown},
2222
caller: {
2323
enableBabelRuntime?: boolean | string,
2424
babelRuntimeModuleName?: string,

‎packages/react-native-babel-preset/src/__tests__/transform-snapshot-test.js‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ const testConfigs = [
158158

159159
function transformCode(
160160
code: string,
161-
options: {[string]: unknown},
161+
options: {[key: string]: unknown},
162162
): string | null {
163163
const result = babel.transformSync(code, {
164164
babelrc: false,
@@ -173,7 +173,7 @@ function transformCode(
173173

174174
function transformCodeWithSourceOptimization(
175175
code: string,
176-
options: {[string]: unknown},
176+
options: {[key: string]: unknown},
177177
): string | null {
178178
const config = preset.getPreset(code, options);
179179
const result = babel.transformSync(code, {
@@ -208,7 +208,10 @@ function ensureDirectoryExists(dir: string): void {
208208
}
209209
}
210210

211-
function makeHeader(description: string, options: {[string]: unknown}): string {
211+
function makeHeader(
212+
description: string,
213+
options: {[key: string]: unknown},
214+
): string {
212215
return `/**
213216
* Copyright (c) Meta Platforms, Inc. and affiliates.
214217
*

‎packages/react-native-codegen/src/generators/RNCodegen.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export type GenerateFunction = (
7777
) => FilesOutput;
7878

7979
export type LibraryGeneratorsFunctions = Readonly<{
80-
[string]: Array<GenerateFunction>,
80+
[key: string]: Array<GenerateFunction>,
8181
}>;
8282

8383
export type LibraryOptions = Readonly<{
@@ -92,9 +92,9 @@ export type LibraryOptions = Readonly<{
9292
}>;
9393

9494
export type SchemasOptions = Readonly<{
95-
schemas: {[string]: SchemaType},
95+
schemas: {[key: string]: SchemaType},
9696
outputDirectory: string,
97-
supportedApplePlatforms?: {[string]: {[string]: boolean}},
97+
supportedApplePlatforms?: {[key: string]: {[key: string]: boolean}},
9898
}>;
9999

100100
export type LibraryGenerators =

0 commit comments

Comments
 (0)