Skip to content

fix(resolver): resolve TypeScript imports of declaration files - #511

Merged
zaebee merged 1 commit into
mainfrom
fix/507-declaration-fallback
Sep 25, 2026
Merged

zaebee merged 1 commit into
mainfrom
fix/507-declaration-fallback

Conversation

@zaebee

@zaebee zaebee commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Closes #507.

Problem

The extractor strips only the last extension, so packages/types/Calendar.d.ts becomes the module packages.types.Calendar.d. Code imports it as @calcom/types/Calendar (or ./Calendar), with no .d. After #506 mapped @calcom/types to packages.types, the candidate packages.types.Calendar still matched no node.

Fix

The TypeScript branch of resolve_import_target tries each candidate (the target itself, then the workspace-package candidates from #504) as written, then with .d. That is the order TypeScript resolves in, so an implementation beside its declaration wins.

Node ids are not changed: stripping .d would rename every declaration node in existing graphs and give foo.ts and foo.d.ts one id.

The candidate logic now lives in module-level functions (_resolve_typescript_import, _workspace_candidates) rather than on SymbolIndex, which would otherwise cross the god-object threshold in test_architecture.py. Same approach as #506; the baseline is not extended.

Tests

tests/unit/test_resolver_ts_declarations.py:

  • a workspace import reaches a declaration module
  • a relative import reaches a declaration module
  • an implementation beside its declaration wins
  • a Python import is not given the suffix
  • end to end through the pipeline with a real .d.ts

Measured on cal.com

before after
unresolved @calcom.* IMPORTS targets 288 39
IMPORTS edges resolved 55.9% 60.4%
impact graph of packages.types.Calendar.d not measured 135 nodes / 229 edges

make format lint type-check doc-coverage pytest: all green (2716 passed, 1 xfailed).

🤖 Generated with Claude Code

`packages/types/Calendar.d.ts` is extracted as the module
`packages.types.Calendar.d`, while code imports it as `@calcom/types/Calendar`
or `./Calendar`. The TypeScript branch of resolve_import_target now tries each
candidate as written and then with the `.d` suffix — the order TypeScript
resolves in, so an implementation beside its declaration wins. Node ids are
left unchanged.

The candidate logic moves from SymbolIndex to module-level functions so the
class stays under the god-object threshold.

Closes #507

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enhances TypeScript import resolution by adding support for declaration files (.d.ts). It replaces the previous workspace import resolution with a new _resolve_typescript_import helper that checks both the exact import target and its declaration counterpart (ending in .d), ensuring that implementation files take precedence over declaration files. A new test suite has been added to verify these changes. I have no feedback to provide on this pull request.

@sonarqubecloud

Copy link
Copy Markdown

@zaebee
zaebee merged commit db8c578 into main Sep 25, 2026
5 checks passed
@zaebee
zaebee deleted the fix/507-declaration-fallback branch September 25, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.d.ts modules keep a .d suffix in their FQN, so imports of them never resolve

1 participant