Skip to content

Commit 456b7ca

Browse files
SamChou19815facebook-github-bot
authored andcommitted
Fix Flow types that use void for a missing value
Summary: Under Flow's `experimental.ts_void`, `void` is TypeScript's `void`, which flows only into `void`, `any` and `unknown`, so a value typed `void` can't be passed where an optional value is expected. This updates Metro's Flow types for projects that check Metro's sources with that option: RAM bundle `encoding` parameters become optional parameters, the bundle output's `save()` returns `Promise<void>`, two test helpers admit `void`, and the two errors whose only fix needs the `undefined` type, which this repository's Flow config doesn't enable, are suppressed. Without that option, `void` and `undefined` are the same type, so nothing changes. Changelog: [Internal] Differential Revision: D133660832
1 parent ba761ed commit 456b7ca

7 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎packages/metro-file-map/src/watchers/__tests__/helpers.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export type EventHelpers = {
5959
nextEvent: (afterFn: () => Promise<void>) => Promise<{
6060
eventType: string,
6161
path: string,
62-
metadata?: ChangeEventMetadata,
62+
metadata?: ChangeEventMetadata | void,
6363
}>,
6464
untilEvent: (
6565
afterFn: () => Promise<void>,
@@ -150,7 +150,7 @@ export const startWatching = async (
150150
Promise.all([
151151
new Promise<{
152152
eventType: string,
153-
metadata?: ChangeEventMetadata,
153+
metadata?: ChangeEventMetadata | void,
154154
path: string,
155155
}>((resolve, reject) => {
156156
const unsubscribe: () => void = watcherInstance.onFileEvent(

‎packages/metro/src/DeltaBundler/Transformer.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ export default class Transformer {
274274
this._workerFarm.transform(
275275
projectRelativePath,
276276
transformerOptions,
277+
// $FlowFixMe[incompatible-type] `void` is not `undefined` under experimental.ts_void
277278
content,
278279
assetUrlPath ?? undefined,
279280
);

‎packages/metro/src/DeltaBundler/__tests__/resolver-test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function dep(name: string): TransformResultDependency {
125125
from: string,
126126
dependency: TransformResultDependency,
127127
resolverOptions?: ResolverInputOptions = {dev: true},
128-
options: void | {assumeFlatNodeModules: boolean},
128+
options?: {assumeFlatNodeModules: boolean},
129129
) =>
130130
dependencyGraph.resolveDependency(
131131
from,

‎packages/metro/src/index.flow.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ async function earlyPortCheck(host: void | string, port: number) {
593593
server.on('error', err => {
594594
reject(err);
595595
});
596+
// $FlowFixMe[incompatible-type] `void` is not `undefined` under experimental.ts_void
596597
server.listen(port, host, undefined, () => resolve());
597598
});
598599
} finally {

‎packages/metro/src/shared/output/RamBundle/as-assets.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function createDir(dirName: string): Promise<void> {
9393
function writeModuleFile(
9494
module: ModuleTransportLike,
9595
modulesDir: string,
96-
encoding: void | 'ascii' | 'utf16le' | 'utf8',
96+
encoding?: 'ascii' | 'utf16le' | 'utf8',
9797
): Promise<unknown> {
9898
const {code, id} = module;
9999
return writeFile(path.join(modulesDir, id + '.js'), code, encoding);
@@ -102,7 +102,7 @@ function writeModuleFile(
102102
function writeModules(
103103
modules: ReadonlyArray<ModuleTransportLike>,
104104
modulesDir: string,
105-
encoding: void | 'ascii' | 'utf16le' | 'utf8',
105+
encoding?: 'ascii' | 'utf16le' | 'utf8',
106106
): Promise<Array<unknown>> {
107107
const writeFiles = modules.map(
108108
(module: ModuleTransportLike): Promise<unknown> =>

‎packages/metro/src/shared/output/RamBundle/as-indexed-file.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ function writeBuffers(
101101

102102
function nullTerminatedBuffer(
103103
contents: string,
104-
encoding: void | 'ascii' | 'utf16le' | 'utf8',
104+
encoding?: 'ascii' | 'utf16le' | 'utf8',
105105
): Buffer {
106106
return Buffer.concat([Buffer.from(contents, encoding), nullByteBuffer]);
107107
}
108108

109109
function moduleToBuffer(
110110
id: number,
111111
code: string,
112-
encoding: void | 'ascii' | 'utf16le' | 'utf8',
112+
encoding?: 'ascii' | 'utf16le' | 'utf8',
113113
): {buffer: Buffer, id: number} {
114114
return {
115115
id,
@@ -194,7 +194,7 @@ function groupCode(
194194
function buildModuleBuffers(
195195
modules: ReadonlyArray<ModuleTransportLike>,
196196
moduleGroups: ModuleGroups,
197-
encoding: void | 'ascii' | 'utf16le' | 'utf8',
197+
encoding?: 'ascii' | 'utf16le' | 'utf8',
198198
): Array<{
199199
buffer: Buffer,
200200
id: number,

‎packages/metro/src/shared/output/bundle.flow.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export async function save(
6969
},
7070
options: OutputOptions,
7171
log: (message: string) => void,
72-
): Promise<unknown> {
72+
): Promise<void> {
7373
const {
7474
bundleOutput,
7575
bundleEncoding: encoding,

0 commit comments

Comments
 (0)