Skip to content

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

Merged
mdonnalley merged 1 commit intooclif:mainfrom
NullSoldier:fix-prompt-types
Oct 31, 2022
Merged

Fix OclifUX.ux.prompt() return type#538
mdonnalley merged 1 commit intooclif:mainfrom
NullSoldier:fix-prompt-types

Conversation

@NullSoldier
Copy link
Copy Markdown
Contributor

@NullSoldier NullSoldier commented Oct 25, 2022

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.

// This should not be valid
const foo: number = await = CliUx.ux.prompt('')
// this should be the normal type
const foo: string = await = CliUx.ux.prompt('')

I tried to sign the CLA but it failed the first time, and every subsequent time now I get You already signed the CLA on 2022-10-25.

@salesforce-cla
Copy link
Copy Markdown

Thanks for the contribution! Before we can merge this, we need @NullSoldier to sign the Salesforce.com Contributor License Agreement.

ygao76
ygao76 previously approved these changes Oct 25, 2022
Comment thread src/cli-ux/action/base.ts
}

public async pauseAsync(fn: () => Promise<any>, icon?: string) {
public async pauseAsync<T extends any>(fn: () => Promise<T>, icon?: string): Promise<T> {
Copy link
Copy Markdown
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.

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.
Comment thread src/cli-ux/prompt.ts
* @returns Promise<string>
*/
export async function anykey(message?: string): Promise<void> {
export async function anykey(message?: string): Promise<string> {
Copy link
Copy Markdown
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.

@mdonnalley mdonnalley merged commit 1599edb into oclif:main Oct 31, 2022
@NullSoldier NullSoldier deleted the fix-prompt-types branch November 1, 2022 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants