Skip trivia after '<' in type-argument arity error spans#4231
Open
Copilot wants to merge 3 commits into
Open
Conversation
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix trivia skipping issue for expected N type arguments
Skip trivia after '<' in type-argument arity error spans
Jun 6, 2026
jakebailey
approved these changes
Jun 6, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aligns TypeScript-Go’s TS2558 (and related type-argument arity) diagnostic spans with upstream TypeScript behavior by skipping trivia immediately after the < token, so underlines start at the first type argument rather than including whitespace/newlines.
Changes:
- Update
getTypeArgumentArityErrorto compute a trivia-skipped diagnostic span for type-argument arity errors (single-signature and overload cases). - Apply the same span adjustment to the JSX intrinsic-element “Expected 0 type arguments” diagnostic.
- Add a new compiler regression test (with baselines) covering single-line and multi-line whitespace/newline trivia after
<.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
internal/checker/checker.go |
Adjust TS2558/overload arity diagnostic span to start at SkipTrivia(...) instead of the raw type-argument-list start. |
internal/checker/jsx.go |
Adjust JSX intrinsic “Expected 0 type arguments” diagnostic span to skip trivia after <. |
testdata/tests/cases/compiler/typeArgumentArityErrorSkipsTrivia.ts |
New regression test for trivia-skipping in type-argument arity diagnostics. |
testdata/baselines/reference/compiler/typeArgumentArityErrorSkipsTrivia.* |
New baselines validating the updated diagnostic span behavior. |
Comment on lines
+554
to
+557
| sourceFile := ast.GetSourceFileOfNode(node) | ||
| typeArgumentList := node.TypeArgumentList() | ||
| loc := core.NewTextRange(scanner.SkipTrivia(sourceFile.Text(), typeArgumentList.Loc.Pos()), typeArgumentList.Loc.End()) | ||
| c.diagnostics.Add(ast.NewDiagnostic(sourceFile, loc, diagnostics.Expected_0_type_arguments_but_got_1, 0, len(typeArguments))) |
Contributor
Author
There was a problem hiding this comment.
Addressed in 54f90e9 by adding a local compiler regression test for both <div< number> /> and the multi-line <div<\n number> /> cases, along with the updated baselines.
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
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.
The TS2558
Expected N type argumentsdiagnostic (and related arity diagnostics) underlined the whitespace/newlines after<, because the span started atTypeArgumentList().Loc, which begins immediately after the<token. TypeScript instead skips trivia, so the span starts at the first type argument.Given:
the error now underlines
string, number(matchingtypescript@6.0) instead ofstring, number, and the multi-line variant points at the line containing the first argument rather than the line withf<.Changes
internal/checker/checker.go—getTypeArgumentArityErrorcomputes the span asskipTrivia(text, typeArgs.Pos())..typeArgs.End(), covering the single-signature, overload-range, and overload single-count diagnostics.internal/checker/jsx.go— Same trivia-skip applied to the JSX intrinsic "Expected 0 type arguments" diagnostic, which shares the message and pattern.testdata/.../typeArgumentArityErrorSkipsTrivia.ts— New compiler test + baselines covering single-line and multi-line trivia after<.