microsoft / microsoft/TypeScript

Too wide diagnostic with array spread

Open
#58,110 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: Related Error Spans
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔎 Search Terms

array spread, diagnostics

🕗 Version & Regression Information
  • This is the behavior in every version I tried and I have reviewed the FAQ
⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.4.4#code/C4TwDgpgBAggRgYygXigIgIZqgH3XbPNBNAbgChyEB7AOwGdgoMAnFjEARgC5ZEBtALooo-TGgA0+NIIpU6jZmw4AmXvARCR-clD1QAdEdbsuE3fvFSLetAXP70AE0nlBQA

💻 Code
type Abc = "a" | "b" | "c";

const array1: Abc[] = ["a", "b"];

const array2: Abc[] = [
    ...array1,
    "a", 
    "b",
    "d",
]
🙁 Actual behavior

The whole contents of array2 is highlighted in red.

🙂 Expected behavior

Only the "d" should be highlighted in red, as it is the only incorrect part of array2. Note that if we remove the spread ...array1, then it works as expected.

Additional information about the issue

With more complicated types/data, this bug can make it pretty hard to diagnose where the problem is.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TypeScript Playground reproduction and the array-spread example in the issue. Trace how diagnostics are produced for the array literal, then verify that only the "d" element is highlighted while the spread and valid elements are not.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.