microsoft / microsoft/TypeScript

`using` transform throws when a for body binding shadows the for head binding

Open
#61,714 6 comments 1 reaction 1 assignee View on GitHub

Nobody has claimed this yet.

Bug Domain: API: Transforms Help Wanted
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

### 🔎 Search Terms

explicit resource management, using, await using, loop initializer, Symbol.dispose, Symbol.asyncDispose, iteration, shadows

### 🕗 Version & Regression Information

- This changed between versions ______ and _______
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about https://github.com/microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs
- I was unable to test this on prior versions because _______

### ⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250516#code/MYGwhgzhAEBiD29oG8C+BYAUAM3gJ2gAoBXCASwDsBzaXJebaAbQF0BKFLaaYeCiAC61E0ALzQKAUwDucRITYBuLKiA

### 💻 Code

```ts
class Foo {}
for (using foo of []) {
const foo = new Foo();
}
```

### 🙁 Actual behavior

The transformed output throws "redeclaration of const foo "

### 🙂 Expected behavior

The transformed output should not throw.

### Additional information about the issue

Babel is also affected by this issue: https://github.com/babel/babel/issues/17318. We plan to wrap the for body within a new block when it contains shadowed binding.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.