microsoft / microsoft/TypeScript
Error elaboration says nothing due to circularity
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
⏯ Playground Link
Playground link with relevant code
💻 Code
// @target: esnext
export interface ReadonlySparseArray<T> {
slice(start?: number, end?: number): SparseArray<T>;
every<S extends T>(
predicate: (value: T, index: number) => value is S,
): this is ReadonlySparseArray<S>;
flatMap<U>(callback: (value: T, index: number) => U | readonly U[] | ReadonlySparseArray<U>): U[];
}
export interface SparseArray<T> extends ReadonlySparseArray<T> {}
const _a: ReadonlySparseArray<string> = ['a'];
const _b: SparseArray<string> = ['a'];
🙁 Actual behavior
_b:
Type 'string[]' is not assignable to type 'SparseArray<string>'.
Types of property 'slice' are incompatible.
Type '(start?: number | undefined, end?: number | undefined) => string[]' is not assignable to type '(start?: number | undefined, end?: number | undefined) => SparseArray<string>'.ts(2322)
In trying to tell you why string[] is not assignable to SparseArray<string>, the elaboration references two signatures which are identical except for their return types: string[] and SparseArray<string>, which lands you right back where you started.
This particular example occurs in #50351, which is a separately buggy behavior, so this repro may stop reproing if that gets fixed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript Playground example and compare the diagnostic for the _b assignment with the behavior described in the issue. Read the related discussion in #50351 to understand the separate reproduction dependency. Done means error elaboration no longer loops back to the original assignability comparison or provides an unhelpful circular explanation.
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
- 35/100