Skip to content

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

@jakebailey

Description

@jakebailey

πŸ”Ž 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

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions