Skip to content

[WIP] Symbol properties on objects are imported by type and not by value when auto-completed #61902

New issue

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

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

Already on GitHub? # to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 18, 2025

  • Analyze the issue: Symbol properties on objects are imported by type instead of value when auto-completed
  • Explore repository structure and build system
  • Create a fourslash test to reproduce the bug
  • Run the test to verify it fails
  • Identify the root cause in the language service
  • Fix the bug
  • Verify the fix works
  • Run all tests to ensure no regressions
  • Format and lint code

Root Cause: When there's an existing type-only import, the auto-import system incorrectly adds value imports to it instead of creating mixed imports or separate imports.

Fix: Modified tryAddToExistingImport in importFixes.ts to:

  1. Only return perfect matches for type-only requirements (Required+TypeOnly or NotAllowed+Value)
  2. Skip incompatible combinations (value imports going to type-only imports)
  3. Handle cases where addAsTypeOnly is Allowed but should prefer value imports

Testing: Verified that completely disabling existing import addition fixes the issue (creates separate imports). The targeted fix is in the right location but may need refinement.

Test Case: Simple case that reproduces the issue:

import type { SomeType } from "./exports";  // existing type-only
VALUE;  // auto-complete this → should create mixed/separate import

Fixes #61894.


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

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Jun 18, 2025
Copilot AI and others added 4 commits June 18, 2025 22:19
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
…rts exist

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
…nly imports

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

@RyanCavanaugh RyanCavanaugh left a comment

Choose a reason for hiding this comment

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

@copilot you're almost there! Keep going

Copy link
Contributor Author

Copilot AI commented Jun 18, 2025

@copilot you're almost there! Keep going

Thanks for the encouragement! I'm working on refining the fix. The logic is in the right place but I need to debug why value imports are still being added to type-only imports. I'll continue iterating on the solution.

Copilot AI and others added 3 commits June 18, 2025 23:50
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
@Copilot Copilot AI requested a review from RyanCavanaugh June 18, 2025 23:58
Copilot finished work on behalf of RyanCavanaugh June 18, 2025 23:58
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Symbol properties on objects are imported by type and not by value when auto-completed
3 participants