microsoft / microsoft/TypeScript
Regression in `asserts` behavior modifying type of `this`
Open
Nobody has claimed this yet.
Needs Investigation
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
🔎 Search Terms
asserts regression
🕗 Version & Regression Information
- This changed between versions 4.9.5 and 5.0.4
⏯ Playground Link
Playground link with relevant code
💻 Code
export class Set<S extends number[] = []> {
insert<_>(x: any): asserts this is Set<[...S, 0]> {}
}
const y: Set = new Set();
y.insert(6);
y
//^?
y.insert(6);
y
//^?
🙁 Actual behavior
In 5.0.4
//^? const y: Set<[]>
//^? const y: Set<[]>
🙂 Expected behavior
In 4.9.5
//^? const y: Set<[0]>
//^? const y: Set<[0,0]>
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 and compare the reported behavior in versions 4.9.5 and 5.0.4. Investigate how the asserts method changes the type of this across successive insert calls. Done means the example narrows y to Set<[0]> after the first call and Set<[0,0]> after the second.
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