Skip to content

feat(cli): respect TypeScript suppression directives for import diagnostics#33280

Draft
ddevilz wants to merge 5 commits intodenoland:mainfrom
ddevilz:fix-ts-suppression-import-diagnostics
Draft

feat(cli): respect TypeScript suppression directives for import diagnostics#33280
ddevilz wants to merge 5 commits intodenoland:mainfrom
ddevilz:fix-ts-suppression-import-diagnostics

Conversation

@ddevilz
Copy link
Copy Markdown

@ddevilz ddevilz commented Apr 15, 2026

feat(cli): respect TypeScript suppression directives for import diagnostics

Fixes #32822


What

Respect TypeScript suppression directives (@ts-ignore and @ts-expect-error) for import-related diagnostics in the CLI type checker.


Why

Previously, Deno's type checker ignored suppression comments for unresolved import errors, making it impossible to suppress known or intentional "module not found" diagnostics.

This behavior was inconsistent with developer expectations when using TypeScript suppression directives.


How

  • Added check_suppressed_at() helper function to centralize suppression checking logic
  • Updated is_resolution_suppressed() to use AST-based detection for accurate positioning
  • Added parsed source caching to avoid re-parsing the same files multiple times
  • Updated GraphWalker to check for suppression before pushing to missing_diagnostics
  • Handles both single-line (//) and block (/* */) comment formats
  • Supports multi-line imports by finding the AST declaration that spans the error position

Behavior

Before

// @ts-ignore
import x from "non-existent-module";
// ❌ Error: module not found

After

// @ts-ignore
import x from "non-existent-module";
// ✅ No diagnostic emitted

Also supports multi-line imports:

// @ts-ignore
import {
  foo,
  bar,
} from "non-existent-module";
// ✅ No diagnostic emitted

Features

  • Single-line comments: // @ts-ignore and // @ts-expect-error
  • Block comments: /* @ts-ignore */ and /* @ts-expect-error */
  • Multi-line imports: Correctly handles imports spanning multiple lines
  • Performance: Caches parsed sources to avoid redundant parsing
  • Precision: Uses AST analysis to accurately position suppression comments
  • Flexible formatting: Handles various whitespace patterns and annotation messages

Design Notes

  • Uses get_leading() to avoid false positives from inline comments on preceding statements
  • AST-based approach ensures accurate handling of complex import structures
  • Caching mechanism improves performance for large codebases
  • Modular design with extracted helper functions improves maintainability

Testing

  • Comprehensive test suite covering all suppression scenarios

  • Tests include:

    • Single-line and block comment suppression
    • Multi-line import handling
    • Whitespace variations and annotation messages
    • Edge cases (blank lines, inline comments, non-suppression cases)
  • All tests pass in x test-spec ts_ignore_import


Implementation Details

  • Files modified: cli/type_checker.rs, cli/factory.rs
  • Performance: Added parsed_source_cache to GraphWalker for efficient parsing
  • Modularity: Extracted check_suppressed_at() helper function to reduce code duplication
  • Accuracy: AST-based detection handles complex import structures correctly

Checklist


AI Disclosure

I used AI assistance to help with implementation, test writing, and drafting this PR description.

ddevilz and others added 5 commits April 6, 2026 20:29
…ostics

This change adds support for @ts-ignore and @ts-expect-error directives
for import-related diagnostics in the CLI type checker.

Features:
- Single-line and block comment support
- Multi-line import handling
- AST-based detection for accuracy
- Parsed source caching for performance
- Comprehensive test coverage

Fixes denoland#32822
- Replace private HashMap<ModuleSpecifier, ParsedSource> on GraphWalker
  with a shared &ParsedSourceCache threaded from TypeChecker, eliminating
  redundant re-parsing of source files during type checking
- Extract duplicated cache-lookup-parse-store logic into check_suppressed_at()
- Add comment on item_start_line == 0 guard explaining u32 underflow prevention
- Document @ts-expect-error / TS2578 limitation in is_resolution_suppressed
- Add blank_line_gap integration spec test (comment + blank line → no suppression)
- Remove tsgo_path and package_json_resolver from RequestNpmState (post-merge cleanup)
- Add production/skip_types fields to NpmInstallerFactoryOptions (post-merge cleanup)
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.

unresolved import errors can't be suppressed with // @ts-expect-error or // @ts-ignore comment

1 participant