Skip to content

Fix panic on CLI --typeRoots with relative path#3866

Merged
jakebailey merged 3 commits into
mainfrom
copilot/fix-tsgo-panics-cli-typeroots
May 15, 2026
Merged

Fix panic on CLI --typeRoots with relative path#3866
jakebailey merged 3 commits into
mainfrom
copilot/fix-tsgo-panics-cli-typeroots

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 15, 2026

CLI list options with file paths (e.g. --typeRoots t) panic because ConvertOptionToAbsolutePath only handles []string, but the CLI parser produces []any from parseListTypeOption. The type assertion silently fails, leaving relative paths unresolved before they hit the VFS.

  • Added []any fallback in ConvertOptionToAbsolutePath to normalize each element to an absolute path
  • Added compiler test typeRootsRelativePath.ts
  • Added unit test TestParseCommandLineTypeRootsRelativePath that calls ParseCommandLine with --typeRoots t and verifies the result is an absolute path, directly exercising the []any code path
# Before: panic: vfs: path "t" is not absolute
# After: error TS2688: Cannot find type definition file for 'n'.
tsgo --ignoreConfig --noEmit --typeRoots t --types n bug.ts

…tions like typeRoots

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/cda3a033-1c28-422d-a1b0-88ed96ae1aef

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix tsgo panics on CLI --typeRoots <relative> Fix panic on CLI --typeRoots with relative path May 15, 2026
Copilot AI requested a review from jakebailey May 15, 2026 18:07
@jakebailey jakebailey marked this pull request as ready for review May 15, 2026 18:09
Copilot AI review requested due to automatic review settings May 15, 2026 18:09
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

Note

Copilot was unable to run its full agentic suite in this review.

Fixes a panic when CLI list options containing relative file paths (e.g. --typeRoots t) reach the VFS without being converted to absolute paths, by ensuring ConvertOptionToAbsolutePath handles the []any shape produced by the CLI list parser.

Changes:

  • Add []any handling in ConvertOptionToAbsolutePath to normalize string elements to absolute paths.
  • Add a new compiler test case for typeRoots with a relative path plus corresponding baselines.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/tsoptions/parsinghelpers.go Normalizes []any list option values containing file paths into absolute paths to prevent VFS panics.
testdata/tests/cases/compiler/typeRootsRelativePath.ts Adds coverage for a relative typeRoots scenario (regression test).
testdata/baselines/reference/compiler/typeRootsRelativePath.types Baseline output for the new test’s type display.
testdata/baselines/reference/compiler/typeRootsRelativePath.symbols Baseline output for the new test’s symbol display.
testdata/baselines/reference/compiler/typeRootsRelativePath.errors.txt Baseline output asserting the expected TS2688 error (instead of a panic).

Comment on lines +645 to +652
if arr, ok := v.([]any); ok {
return core.Map(arr, func(item any) any {
if s, isStr := item.(string); isStr {
return tspath.GetNormalizedAbsolutePath(s, cwd)
}
return item
}), true
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot investigate

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The reviewer was correct — the compiler test exercises the []string path via the test harness (which manually normalizes TypeRoots on lines 183-185 of harnessutil.go), not the []any CLI parser path. Added a unit test TestParseCommandLineTypeRootsRelativePath in 97e9f6b that calls ParseCommandLine with --typeRoots t and asserts the result is an absolute path, directly exercising the []any branch.

Comment on lines 642 to +652
return tspath.GetNormalizedAbsolutePath(item, cwd)
}), true
}
if arr, ok := v.([]any); ok {
return core.Map(arr, func(item any) any {
if s, isStr := item.(string); isStr {
return tspath.GetNormalizedAbsolutePath(s, cwd)
}
return item
}), true
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That won't work, slices are invariant

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, Go slices are invariant so []any and []string can't share a common generic handler. The two branches are necessary.

Copilot AI requested a review from jakebailey May 15, 2026 18:33
@jakebailey jakebailey added this pull request to the merge queue May 15, 2026
Merged via the queue into main with commit 4d18200 May 15, 2026
21 checks passed
@jakebailey jakebailey deleted the copilot/fix-tsgo-panics-cli-typeroots branch May 15, 2026 22:14
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.

tsgo panics on CLI --typeRoots <relative> when typeRoots is consulted

4 participants