Skip to content

[WIP] Invalid quick fix for function returning Promise<unknown> with isolatedDeclarations #61856

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
wants to merge 2 commits into from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 12, 2025

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original issue description:

🔎 Search Terms

isolatedDeclarations, quick fix, promise

🕗 Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?isolatedDeclarations=true#code/KYDwDg9gTgLgBAMwK4DsDGMCWEVwO4CGmMAqigNYR4oAUAtgM4BccKSdARsFAJRwDeAKDhwowGEii4UwPHAAKUCHUwNgNGnwC8APgEBfHgG5B+waEixEqDNlyFiAZRhRMKAOb1mrdl14DhUXFJaVkFJRU1AB4GFzd3HQ1tPX5DEzMgA

💻 Code

export function waitUnkown(ms: number) {
  return new Promise(() => {});
}
export function waitString(ms: number) {
  return new Promise<string>(() => {});
}

🙁 Actual behavior

The quick fix for waitUnknown is "Add return type Promise"
Image

Which annotates the return type as : Promise -- which is a type error as the argument to the promise type is required.

🙂 Expected behavior

The quick fix for waitUnknown is "Add return type Promise", which is the correct, currently inferred type.

Additional information about the issue

I was trying to codemod Canva's codebase using ts-fix and this bug created a bunch of bad code which I would need to fix up by hand.

Fixes #61642.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@RyanCavanaugh
Copy link
Member

@copilot try again

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 12, 2025

@copilot try again

I've successfully implemented a fix for the Promise<unknown> quick fix issue. The problem was in the endOfRequiredTypeParameters function which was incorrectly minimizing Promise<unknown> to just Promise. The fix adds special handling to preserve the <unknown> type argument, ensuring the quick fix now correctly suggests : Promise<unknown> instead of the invalid : Promise. See commit 0e9439b.

Copilot finished work on behalf of RyanCavanaugh June 12, 2025 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Error loading sessions

Retrying...

Successfully merging this pull request may close these issues.

Invalid quick fix for function returning Promise<unknown> with isolatedDeclarations
3 participants