microsoft / microsoft/TypeScript
"used before being assigned" fires on LHS inside parens/type assertion
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
### 🔎 Search Terms
used before being assigned cast type assertion left side LHS parens parentheses
### 🕗 Version & Regression Information
- This is the behavior changed in 5.7
### ⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250725#code/CYUwxgNghgTiAEAzArgOzAFwJYHtX1AGcwYsAjEAClSgFsQAueQjU1AcwBolUnKBKeAF4AfPABuOLMH5NJ0gLAAoZaEiwEKdNjzwKiHHACiUMAAtKiXvAHCx8mXKnAA3MtXhoceOsKF4AMo49BhmWBzwAN7K8Eg4OAJMqMi0FDBuSgC+7kpEJORUAESF3LaiUTHwECAYetBmTEEhYRwZlfqGICbmlGVi0UqxsZRk9fBQ-lCoAJ6CQj7QfvAA6jgA7lGZGbGZ-Mq7OR7EpBSUxaVz-ZXVtaNQDYHBNS3sbYN6IAbGphZ9Fe-DO5mOYLCb+VYbSJbSoHLJ7JRAA
### 💻 Code
```ts
declare function describe(name: string, fn: () => void): void
declare function beforeEach(fn: () => void): void;
declare class Something {
foo(): number;
}
describe("", () => {
let blah: Something;
beforeEach(() => {
(blah as any) = class Wow {};
})
})
describe("", () => {
let blah: Something;
beforeEach(() => {
(blah) = class Wow {};
})
})
```
### 🙁 Actual behavior
Both assignments error with `is used before being assigned`.
### 🙂 Expected behavior
Neither should, as they are writes.
### Additional information about the issue
_No response_
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.
Assessment
This issue has not been assessed yet.