Skip to content

fix(tsoptions): validate project reference fields#4494

Open
TorinAsakura wants to merge 4 commits into
microsoft:mainfrom
TorinAsakura:fix/project-reference-validation
Open

fix(tsoptions): validate project reference fields#4494
TorinAsakura wants to merge 4 commits into
microsoft:mainfrom
TorinAsakura:fix/project-reference-validation

Conversation

@TorinAsakura

@TorinAsakura TorinAsakura commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Validate project reference path and circular fields before constructing ProjectReference values.
  • Report diagnostics for missing, non-string, or empty reference.path instead of silently dropping the reference or panicking.
  • Report diagnostics for non-boolean reference.circular.
  • Cover invalid project reference diagnostics in tsc and tsc --build baseline tests.

Fixes #4269.

Before

A project reference with a non-string path could panic while parsing the config:

panic: interface conversion: interface {} is bool, not string
...
internal/tsoptions.parseProjectReference

A project reference with an empty path was silently omitted from the build graph:

Projects in this build:
    * <tmp>/flat/tsconfig.build.json

After

Invalid project reference fields are reported as config diagnostics instead of panicking; the repro includes the referenced config so this only shows the project-reference field diagnostics:

<tmp>/flat/tsconfig.json(1,43): error TS5024: Compiler option 'reference.path' requires a value of type string.
<tmp>/flat/tsconfig.json(1,49): error TS5024: Compiler option 'reference.path' requires a value of type string.
<tmp>/flat/tsconfig.json(1,96): error TS5024: Compiler option 'reference.circular' requires a value of type boolean.
<tmp>/flat/tsconfig.json(1,111): error TS18051: Compiler option 'reference.path' cannot be given an empty string.
exit status 2

An empty project reference path is now diagnosed instead of silently ignored:

<tmp>/flat/tsconfig.build.json(1,24): error TS18051: Compiler option 'reference.path' cannot be given an empty string.
exit status 2

Validation

  • go test ./internal/execute/tsctests -run 'TestTscProjectReferences|TestBuildConfigFileErrors'
  • go test ./internal/tsoptions ./internal/execute/...

Copilot AI review requested due to automatic review settings June 30, 2026 20:14
Comment thread internal/tsoptions/tsconfigparsing_test.go Outdated

Copilot AI 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.

Pull request overview

This PR hardens tsconfig project reference parsing in internal/tsoptions by validating references[].path and references[].circular before constructing core.ProjectReference entries, converting previously panicking/silent-failure scenarios into config diagnostics (Fixes #4269).

Changes:

  • Added typed/empty-string validation for references[].path and type validation for references[].circular, emitting appropriate diagnostics instead of panicking or omitting references.
  • Introduced a helper to attach diagnostics to the most relevant references[] property node when parsing from a JSON SourceFile.
  • Added unit tests covering invalid project reference fields for both source-file parsing and object-based config parsing.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/tsoptions/tsconfigparsing.go Validates references entries, emits targeted diagnostics, and adds a helper for precise diagnostic locations.
internal/tsoptions/tsconfigparsing_test.go Adds test coverage for invalid references[].path / references[].circular across both config parsing entry points.
internal/tsoptions/parsinghelpers.go Makes project reference parsing type-safe by returning a structured parse result instead of using unsafe type assertions.

Copilot AI 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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

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.

Fatal error when project reference objects have unexpected types for path and circular

3 participants