Skip to content

Avoid providing promise methods as completions at return positions in non-async functions #59298

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

Closed
Andarist opened this issue Jul 16, 2024 · 0 comments Β· Fixed by #59316
Closed
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Milestone

Comments

@Andarist
Copy link
Contributor

πŸ”Ž Search Terms

completions promise return expression type async members

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240716#code/C4TwDgpgBAsiAq5oF4oG8CwAoKUBmA9gQFxQDOwATgJYB2A5gNzYC+zW2eArrQMbDUCtKMAgUAFLwBGpcQEooyAHywESKAB8oABUoEAttTIQAPHESQlCtC2zZRE+YpXjMOKAHoAVAEYvH1jk5diA

πŸ’» Code

type MyType = {
  foo: string;
};

function test(cb: () => MyType | Promise<MyType>) {}

test(() => ({
  /*1*/
}));

πŸ™ Actual behavior

Completions provided at the marker position include catch, foo and then

πŸ™‚ Expected behavior

It would be great if in a situation like this promise methods would get at least deprioritized and if they would appear at the bottom of the list.

Additional information about the issue

It's technically okay to return thenables compatible with Promise interface but it should be a very rare situation. I think a DX win here would justify hiding those members completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants