Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OclifUX.ux.prompt() return type #538

Merged
merged 1 commit into from Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will help with backwards compatability, in the case that typescript cannot infer 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> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My change has revealed that this code was broken. It was typed as returning void but actually it was returning a string.

const tty = Boolean(process.stdin.setRawMode)
if (!message) {
message = tty ?
Expand Down