microsoft / microsoft/TypeScript

"used before being assigned" fires on LHS inside parens/type assertion

Open
#62,127 1 comment 1 reaction 1 assignee View on GitHub

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

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.