Preserve ts-check across reference directives#4061
Open
Copilot wants to merge 4 commits into
Open
Conversation
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
RyanCavanaugh
requested changes
May 27, 2026
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
RyanCavanaugh
approved these changes
May 27, 2026
Contributor
There was a problem hiding this comment.
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
pragmain thets-check/ts-nocheckcase. - Add a regression compiler test covering
.tsand.jsfiles with@ts-checkfollowed 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
// @ts-checkwas being overridden by later triple-slash reference pragmas, causing checked files to be treated likets-nocheck. This affected JS and TS files when a reference directive followed the check directive.Parser directive handling
ts-check/ts-nocheckpragmas.Regression coverage
@ts-checkfollowed by/// <reference lib="dom" />in both.tsand.jsinputs.