microsoft / microsoft/TypeScript
Incorrect report of self-referencing type for static fields
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
### 🔎 Search Terms
TS7022
implicitly has type 'any'
### 🕗 Version & Regression Information
- The issue applies to all TypeScript 5 versions and TypeScript 6 nightly
### ⏯ Playground Link
https://www.typescriptlang.org/play/?ts=6.0.0-dev.20251006#code/GYVwdgxgLglg9mABDAJgHgCoD4AUAPALkQwEoiNEBvAKEUQCcBTKEepPagX2uogQGcoiAGJw4iALzIUOCABsAhv35VaiQQtgQGjBSgRyAnomBjJ0nABYATCUQB6e4gCi9enHrEAygHYADNbWXCQ8fGCCiADyANbm8koqNHQaWjp6Bsam4lKoVrYOTgBy4oxuHlzUQA
### 💻 Code
```ts
function id(x: T): T {
return x
}
const Foo = id(class {
static readonly foo = id(42) // Error TS7022
})
const Ok = class {
static readonly foo = id(42) // No error
}
```
### 🙁 Actual behavior
Type error TS7022 reported
### 🙂 Expected behavior
No type error
### Additional information about the issue
_No response_
Contributor guide
Research direction
Start with the linked TypeScript Playground and reproduce the TS7022 diagnostic using the two class examples. Compare the diagnostic behavior between the self-referencing static field and the equivalent standalone class, then trace the compiler's type inference and diagnostic path. Done means the reported example no longer produces TS7022 while the relevant error behavior remains intact.
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
- 42/100