TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

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

Open Copilot opened this issue 7 months ago • 0 comments

  • [x] Analyze the issue: Symbol properties on objects are imported by type instead of value when auto-completed
  • [x] Explore repository structure and build system
  • [x] Create a fourslash test to reproduce the bug
  • [x] Run the test to verify it fails
  • [x] Identify the root cause in the language service
  • [x] 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.

Copilot avatar Jun 18 '25 22:06 Copilot