Skip to content

Commit

Permalink
Use undefined rather than void
Browse files Browse the repository at this point in the history
`void` should only be used for return types of functions that do not return anything (not even undefined).

See https://www.typescriptlang.org/docs/handbook/2/functions.html#void
  • Loading branch information
petebacondarwin committed Jan 14, 2022
1 parent fc112d7 commit 1d7781e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 48 deletions.
12 changes: 6 additions & 6 deletions packages/wrangler/src/api/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ export interface CfWorkerInit {
/**
* The name of the worker.
*/
name: string | void;
name: string | undefined;
/**
* The entrypoint module.
*/
main: CfModule;
/**
* The list of additional modules.
*/
modules: void | CfModule[];
modules: undefined | CfModule[];
/**
* All the bindings
*/
Expand All @@ -130,10 +130,10 @@ export interface CfWorkerInit {
vars?: CfVars;
services?: CfService[];
};
migrations: void | CfDurableObjectMigrations;
compatibility_date: string | void;
compatibility_flags: void | string[];
usage_model: void | "bundled" | "unbound";
migrations: undefined | CfDurableObjectMigrations;
compatibility_date: string | undefined;
compatibility_flags: undefined | string[];
usage_model: undefined | "bundled" | "unbound";
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,5 @@ export type Config = {
usage_model?: UsageModel; // inherited
// top level
build?: Build;
env?: { [envName: string]: void | Env };
env?: { [envName: string]: undefined | Env };
};
76 changes: 38 additions & 38 deletions packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ import { usePreviewServer } from "./proxy";
import { execa } from "execa";
import { watch } from "chokidar";

type CfScriptFormat = void | "modules" | "service-worker";
type CfScriptFormat = undefined | "modules" | "service-worker";

export type DevProps = {
name?: string;
entry: string;
port?: number;
format: CfScriptFormat;
accountId: void | string;
accountId: undefined | string;
initialMode: "local" | "remote";
jsxFactory: void | string;
jsxFragment: void | string;
jsxFactory: undefined | string;
jsxFragment: undefined | string;
bindings: CfWorkerInit["bindings"];
public: undefined | string;
site: void | string;
compatibilityDate: void | string;
compatibilityFlags: void | string[];
usageModel: void | "bundled" | "unbound";
site: undefined | string;
compatibilityDate: undefined | string;
compatibilityFlags: undefined | string[];
usageModel: undefined | "bundled" | "unbound";
buildCommand: {
command?: undefined | string;
cwd?: undefined | string;
Expand Down Expand Up @@ -130,18 +130,18 @@ function Dev(props: DevProps): JSX.Element {
}

function Remote(props: {
name: void | string;
bundle: EsbuildBundle | void;
name: undefined | string;
bundle: EsbuildBundle | undefined;
format: CfScriptFormat;
public: undefined | string;
site: void | string;
site: undefined | string;
port: number;
accountId: void | string;
apiToken: void | string;
accountId: undefined | string;
apiToken: undefined | string;
bindings: CfWorkerInit["bindings"];
compatibilityDate: string | void;
compatibilityFlags: void | string[];
usageModel: void | "bundled" | "unbound";
compatibilityDate: string | undefined;
compatibilityFlags: undefined | string[];
usageModel: undefined | "bundled" | "unbound";
}) {
assert(props.accountId, "accountId is required");
assert(props.apiToken, "apiToken is required");
Expand Down Expand Up @@ -174,12 +174,12 @@ function Remote(props: {
return null;
}
function Local(props: {
name: void | string;
bundle: EsbuildBundle | void;
name: undefined | string;
bundle: EsbuildBundle | undefined;
format: CfScriptFormat;
bindings: CfWorkerInit["bindings"];
public: void | string;
site: void | string;
public: undefined | string;
site: undefined | string;
port: number;
}) {
const { inspectorUrl } = useLocalWorker({
Expand All @@ -194,8 +194,8 @@ function Local(props: {
}

function useLocalWorker(props: {
name: void | string;
bundle: EsbuildBundle | void;
name: undefined | string;
bundle: EsbuildBundle | undefined;
format: CfScriptFormat;
bindings: CfWorkerInit["bindings"];
port: number;
Expand Down Expand Up @@ -320,7 +320,7 @@ function useLocalWorker(props: {
return { inspectorUrl };
}

function useTmpDir(): string | void {
function useTmpDir(): string | undefined {
const [directory, setDirectory] = useState<DirectoryResult>();
const handleError = useErrorHandler();
useEffect(() => {
Expand Down Expand Up @@ -358,8 +358,8 @@ function useCustomBuild(
cwd?: undefined | string;
watch_dir?: undefined | string;
}
): void | string {
const [entry, setEntry] = useState<string | void>(
): undefined | string {
const [entry, setEntry] = useState<string | undefined>(
// if there's no build command, just return the expected entry
props.command ? null : expectedEntry
);
Expand Down Expand Up @@ -430,12 +430,12 @@ type EsbuildBundle = {
};

function useEsbuild(props: {
entry: void | string;
destination: string | void;
staticRoot: void | string;
jsxFactory: string | void;
jsxFragment: string | void;
}): EsbuildBundle | void {
entry: undefined | string;
destination: string | undefined;
staticRoot: undefined | string;
jsxFactory: string | undefined;
jsxFragment: string | undefined;
}): EsbuildBundle | undefined {
const { entry, destination, staticRoot, jsxFactory, jsxFragment } = props;
const [bundle, setBundle] = useState<EsbuildBundle>();
useEffect(() => {
Expand Down Expand Up @@ -502,18 +502,18 @@ function useEsbuild(props: {
}

function useWorker(props: {
name: void | string;
bundle: EsbuildBundle | void;
name: undefined | string;
bundle: EsbuildBundle | undefined;
format: CfScriptFormat;
modules: CfModule[];
accountId: string;
apiToken: string;
bindings: CfWorkerInit["bindings"];
sitesFolder: void | string;
sitesFolder: undefined | string;
port: number;
compatibilityDate: string | void;
compatibilityFlags: string[] | void;
usageModel: void | "bundled" | "unbound";
compatibilityDate: string | undefined;
compatibilityFlags: string[] | undefined;
usageModel: undefined | "bundled" | "unbound";
}): CfPreviewToken | undefined {
const {
name,
Expand Down Expand Up @@ -637,7 +637,7 @@ const SLEEP_DURATION = 2000;
// really need a first class api for this
const hostNameRegex = /userHostname="(.*)"/g;
async function findTunnelHostname() {
let hostName: string;
let hostName: string | undefined;
while (!hostName) {
try {
const resp = await fetch("http://localhost:8789/metrics");
Expand Down
6 changes: 3 additions & 3 deletions packages/wrangler/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { Config } from "./config";
import makeModuleCollector from "./module-collection";
import { syncAssets } from "./sites";

type CfScriptFormat = void | "modules" | "service-worker";
type CfScriptFormat = undefined | "modules" | "service-worker";

type Props = {
config: Config;
Expand All @@ -26,8 +26,8 @@ type Props = {
triggers?: (string | number)[];
routes?: (string | number)[];
legacyEnv?: boolean;
jsxFactory: void | string;
jsxFragment: void | string;
jsxFactory: undefined | string;
jsxFragment: undefined | string;
};

function sleep(ms: number) {
Expand Down

0 comments on commit 1d7781e

Please sign in to comment.