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

Conversation

NullSoldier
Copy link
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

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
@@ -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.

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.
*/
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.

@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.

None yet

3 participants