Skip to content

Commit 348d068

Browse files
committed
Re-allow users to not select an emulator UI port.
Fixes #8621 Sorry; somehow I missed that there was a case where numbers are not required. Keeps the library's behavior of assuming that numbers are required, but allows explicitly overwriting this with a "reququired: false". This is the only value that can be provided to "required". Using type magic, the return type of number can only be defined if "required: false" is passed in.
1 parent cc1aa4b commit 348d068

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/init/features/emulators.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,10 @@ export async function doSetup(setup: Setup, config: Config) {
8181
});
8282

8383
if (ui.enabled) {
84-
ui.port = await number(
85-
`Which port do you want to use for the ${clc.underline(uiDesc)} (leave empty to use any available port)?`,
86-
);
87-
88-
// Parse the input as a number
89-
const portNum = Number.parseInt(ui.port as any);
90-
ui.port = isNaN(portNum) ? undefined : portNum;
84+
ui.port = await number({
85+
message: `Which port do you want to use for the ${clc.underline(uiDesc)} (leave empty to use any available port)?`,
86+
required: false,
87+
});
9188
}
9289
}
9390

src/prompt.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,12 @@ export async function number(message: string): Promise<number>;
214214
*/
215215
export async function number(opts: NumberOptions): Promise<number>;
216216

217-
export async function number(opts: string | NumberOptions): Promise<number> {
217+
/**
218+
* Prompt a user for an optional number.
219+
*/
220+
export async function number(opts: NumberOptions & { required: false }): Promise<number | undefined>;
221+
222+
export async function number(opts: string | NumberOptions): Promise<number | undefined> {
218223
if (typeof opts === "string") {
219224
opts = { message: opts };
220225
} else {
@@ -224,7 +229,7 @@ export async function number(opts: string | NumberOptions): Promise<number> {
224229
}
225230
}
226231

227-
return (await inquirer.number({ ...opts, required: true }))!;
232+
return await inquirer.number({ required: true, ...opts });
228233
}
229234

230235
/**

0 commit comments

Comments
 (0)