microsoft / microsoft/TypeScript

Regression in `asserts` behavior modifying type of `this`

Open
#55,063 0 comments 1 reaction 0 assignees View on GitHub

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.