Skip to content

Commit

Permalink
codemod objects to interfaces where they appear as supertypes of classes
Browse files Browse the repository at this point in the history
Summary:
Flow is changing the behavior of object types to no longer be valid supertypes of classes. This replaces object types when they appear as supertypes of classes to be interfaces to avoid errors when this change rolls out.

Changelog: [Internal]

Reviewed By: pieterv

Differential Revision: D27193522

fbshipit-source-id: c3e3fca8a4cacd90770a95b773ff2c659774b9a6
  • Loading branch information
dsainati1 authored and facebook-github-bot committed Mar 23, 2021
1 parent 944fa6c commit e81a2cd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 28 deletions.
3 changes: 1 addition & 2 deletions packages/metro-cache/src/types.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

'use strict';

export type CacheStore<T> = {
export type CacheStore<T> = interface {
get(key: Buffer): ?T | Promise<?T>,
set(key: Buffer, value: T): void | Promise<void>,
clear(): void | Promise<void>,
...
};
10 changes: 5 additions & 5 deletions packages/metro/src/lib/TerminalReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export type TerminalReportableEvent =

type BuildPhase = 'in_progress' | 'done' | 'failed';

type SnippetError = ErrnoError & {
filename?: string,
snippet?: string,
...
};
type SnippetError = ErrnoError &
interface {
filename?: string,
snippet?: string,
};

const GLOBAL_CACHE_DISABLED_MESSAGE_FORMAT =
'The global cache is now disabled because %s';
Expand Down
3 changes: 1 addition & 2 deletions packages/metro/src/lib/attachWebsocketServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import type {Server as HttpServer} from 'http';
import type {Server as HttpsServer} from 'https';

type WebsocketServiceInterface<T> = {
type WebsocketServiceInterface<T> = interface {
+onClientConnect: (
url: string,
sendFn: (data: string) => void,
Expand All @@ -25,7 +25,6 @@ type WebsocketServiceInterface<T> = {
message: string,
sendFn: (data: string) => void,
) => mixed,
...
};

type HMROptions<TClient> = {
Expand Down
24 changes: 12 additions & 12 deletions packages/metro/src/lib/formatBundlingError.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ const {AmbiguousModuleResolutionError} = require('metro-core');

import type {FormattedError} from 'metro-runtime/src/modules/types.flow';

export type CustomError = Error & {
type?: string,
filename?: string,
lineNumber?: number,
errors?: Array<{
description: string,
filename: string,
lineNumber: number,
...
}>,
...
};
export type CustomError = Error &
interface {
type?: string,
filename?: string,
lineNumber?: number,
errors?: Array<{
description: string,
filename: string,
lineNumber: number,
...
}>,
};

function formatBundlingError(error: CustomError): FormattedError {
if (error instanceof AmbiguousModuleResolutionError) {
Expand Down
2 changes: 1 addition & 1 deletion packages/metro/src/lib/reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export type ReportableEvent =
* TerminalReporter, that should be the only place in the application should
* access the `terminal` module (nor the `console`).
*/
export type Reporter = {update(event: ReportableEvent): void, ...};
export type Reporter = interface {update(event: ReportableEvent): void};

/**
* A standard way to log a warning to the terminal. This should not be called
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,18 @@ import type {

export type DirExistsFn = (filePath: string) => boolean;

export type Packageish = {
export type Packageish = interface {
path: string,
redirectRequire(
toModuleName: string,
mainFields: $ReadOnlyArray<string>,
): string | false,
getMain(mainFields: $ReadOnlyArray<string>): string,
...
};

export type Moduleish = {
export type Moduleish = interface {
+path: string,
getPackage(): ?Packageish,
...
};

/**
Expand All @@ -63,14 +61,13 @@ export type ModuleMap = {
...
};

export type ModuleishCache<TModule, TPackage> = {
export type ModuleishCache<TModule, TPackage> = interface {
getPackage(
name: string,
platform?: string,
supportsNativePlatform?: boolean,
): TPackage,
getModule(path: string): TModule,
...
};

type Options<TModule, TPackage> = {|
Expand Down

0 comments on commit e81a2cd

Please sign in to comment.