Skip to content

Handle numbers in tsconfig parsing#3502

Merged
jakebailey merged 1 commit intomainfrom
jabaile/fix-3493
Apr 22, 2026
Merged

Handle numbers in tsconfig parsing#3502
jakebailey merged 1 commit intomainfrom
jabaile/fix-3493

Conversation

@jakebailey
Copy link
Copy Markdown
Member

@jakebailey jakebailey commented Apr 22, 2026

This has never worked and we have never noticed because maxNodeModuleJsDepth is actually our only int compiler option that isn't a new one like --checkers. Wow!

Fixes #3493

Copy link
Copy Markdown
Member

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

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

Does this mean this is totally untested in actual compiler tests?? 😮

@jakebailey
Copy link
Copy Markdown
Member Author

No, the feature works, it's just that they all go through // @maxNodeModuleJsDepth: 3 etc parsing.

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 tsconfig parsing so numeric compiler options (notably maxNodeModuleJsDepth) are correctly read from JSON and surfaced in the parsed CompilerOptions, aligning behavior with expectations for number-typed options in config files.

Changes:

  • Extend numeric option parsing to accept float64 values (as produced by JSON parsing) when populating *int fields.
  • Update tsconfig parsing baselines to include maxNodeModuleJsDepth in CompilerOptions output for both json and jsonSourceFile APIs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
internal/tsoptions/parsinghelpers.go Updates parseNumber to accept JSON numeric (float64) inputs.
testdata/baselines/reference/config/tsconfigParsing/parses tsconfig with compilerOptions, files, include, and exclude with json api.js Baseline updated to reflect correct parsing of maxNodeModuleJsDepth.
testdata/baselines/reference/config/tsconfigParsing/parses tsconfig with compilerOptions, files, include, and exclude with jsonSourceFile api.js Baseline updated to reflect correct parsing of maxNodeModuleJsDepth.

Comment on lines +66 to +69
if num, ok := value.(float64); ok {
n := int(num)
return &n
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

Converting a JSON number (float64) to int without bounds checking can yield implementation-dependent results when the value is outside the target int range, and will also silently truncate fractional values. Consider validating the float64 is within [minInt, maxInt] (and, if desired, that it’s an integer value) before converting; otherwise return nil or emit a diagnostic so an invalid tsconfig value can’t become a surprising negative/garbled int (e.g., affecting maxDepth handling).

Copilot uses AI. Check for mistakes.
@jakebailey jakebailey added this pull request to the merge queue Apr 22, 2026
Merged via the queue into main with commit e7283bb Apr 22, 2026
25 checks passed
@jakebailey jakebailey deleted the jabaile/fix-3493 branch April 22, 2026 21:47
jakebailey added a commit that referenced this pull request Apr 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.

maxNodeModuleJsDepth + allowJs does not load types from a CommonJS dependency in node_modules (TS7016 vs tsc 6.0 success)

3 participants