Skip to content

Preserve ts-check across reference directives#4061

Open
Copilot wants to merge 4 commits into
mainfrom
copilot/reference-directive-ts-check-issue
Open

Preserve ts-check across reference directives#4061
Copilot wants to merge 4 commits into
mainfrom
copilot/reference-directive-ts-check-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 27, 2026

// @ts-check was being overridden by later triple-slash reference pragmas, causing checked files to be treated like ts-nocheck. This affected JS and TS files when a reference directive followed the check directive.

  • Parser directive handling

    • Limit check-mode selection to ts-check / ts-nocheck pragmas.
    • Preserve existing “last check directive wins” behavior without letting reference pragmas participate.
  • Regression coverage

    • Add a compiler test covering @ts-check followed by /// <reference lib="dom" /> in both .ts and .js inputs.
// @ts-check
/// <reference lib="dom" />

let a = "";
a = 1; // still reports TS2322

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix reference directive impact on ts-check behavior Preserve ts-check across reference directives May 27, 2026
Copilot AI requested a review from RyanCavanaugh May 27, 2026 17:29
Comment thread internal/parser/parser.go Outdated
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
@RyanCavanaugh RyanCavanaugh marked this pull request as ready for review May 27, 2026 22:31
Copilot AI review requested due to automatic review settings May 27, 2026 22:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a parser bug where // @ts-check could be overridden by subsequent triple-slash reference pragmas, because the inner loop in processPragmasIntoFields iterated over all pragmas (not just check directives) and set Enabled based on whether each pragma's name was "ts-check". The fix removes the redundant inner loop, relying on the outer switch's ts-check/ts-nocheck case to provide the correct pragma.

Changes:

  • Replace the inner pragma loop with direct use of the current pragma in the ts-check/ts-nocheck case.
  • Add a regression compiler test covering .ts and .js files with @ts-check followed by /// <reference lib="dom" />.
  • Add the corresponding errors baseline.
Show a summary per file
File Description
internal/parser/parser.go Fix CheckJsDirective resolution to use only the current ts-check/ts-nocheck pragma.
testdata/tests/cases/compiler/tsCheckPreservedAfterReference.ts New regression test for both TS and JS files.
testdata/baselines/reference/compiler/tsCheckPreservedAfterReference.errors.txt Expected TS2322 baseline for the regression test.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 0

@RyanCavanaugh RyanCavanaugh added this to the TypeScript 7.0 RC milestone May 28, 2026
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.

reference directive caused issue with ts-check

3 participants