Skip to content

Commit

Permalink
Fix OclifUX.ux.prompt() return type
Browse files Browse the repository at this point in the history
It's been a long standing issue that prompt returns a Promise<any> when
it clearly should return Promise<string>. It's because the wrapper
methods pauseAsync() don't forward their types along from the wrapped
functions.
  • Loading branch information
NullSoldier committed Oct 25, 2022
1 parent 56698d6 commit 068653d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/cli-ux/action/base.ts
Expand Up @@ -92,7 +92,7 @@ export class ActionBase {
task.status = status
}

public async pauseAsync(fn: () => Promise<any>, icon?: string) {
public async pauseAsync<T extends any>(fn: () => Promise<T>, icon?: string): Promise<T> {
const task = this.task
const active = task && task.active
if (task && active) {
Expand Down
8 changes: 4 additions & 4 deletions src/cli-ux/prompt.ts
Expand Up @@ -120,9 +120,9 @@ function _prompt(name: string, inputOptions: Partial<IPromptOptions> = {}): Prom
* prompt for input
* @param name - prompt text
* @param options - @see IPromptOptions
* @returns void
* @returns Promise<string>
*/
export function prompt(name: string, options: IPromptOptions = {}) {
export function prompt(name: string, options: IPromptOptions = {}): Promise<string> {
return config.action.pauseAsync(() => {
return _prompt(name, options)
}, chalk.cyan('?'))
Expand All @@ -149,9 +149,9 @@ export function confirm(message: string): Promise<boolean> {
/**
* "press anykey to continue"
* @param message - optional message to display to user
* @returns Promise<void>
* @returns Promise<string>
*/
export async function anykey(message?: string): Promise<void> {
export async function anykey(message?: string): Promise<string> {
const tty = Boolean(process.stdin.setRawMode)
if (!message) {
message = tty ?
Expand Down

0 comments on commit 068653d

Please sign in to comment.