Skip to content

Skip trivia after '<' in type-argument arity error spans#4231

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-expected-n-type-arguments
Open

Skip trivia after '<' in type-argument arity error spans#4231
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-expected-n-type-arguments

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 6, 2026

The TS2558 Expected N type arguments diagnostic (and related arity diagnostics) underlined the whitespace/newlines after <, because the span started at TypeArgumentList().Loc, which begins immediately after the < token. TypeScript instead skips trivia, so the span starts at the first type argument.

Given:

declare function f<T>(a: T): T;

f<   string, number>("a");

the error now underlines string, number (matching typescript@6.0) instead of string, number, and the multi-line variant points at the line containing the first argument rather than the line with f<.

Changes

  • internal/checker/checker.gogetTypeArgumentArityError computes the span as skipTrivia(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 <.

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
Copilot AI requested a review from jakebailey June 6, 2026 21:24
@jakebailey jakebailey marked this pull request as ready for review June 6, 2026 21:26
Copilot AI review requested due to automatic review settings June 6, 2026 21:26
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

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 getTypeArgumentArityError to 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 thread internal/checker/jsx.go
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)))
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.

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>
Copilot AI requested a review from jakebailey June 6, 2026 22:01
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.

'Expected N type arguments' position does not skip trivia after '<'

3 participants