microsoft / microsoft/TypeScript
Enforce definite initialization of `static` members
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Is there some clever reason why TSC can't check this (maybe... related to semantics of JS inheritance?)?
TypeScript Version: 3.2.0-dev.20181011
Search Terms: strictPropertyInitialization, static, initialized, uninitialized, assigned, property
Code
class A {
static s: number
a() {
A.s * 3 // Should be a compile error
}
}
A.s * 7 // Should be an compile error
Expected behavior: Both lines should produce compile errors.
Actual behavior: Both lines result in runtime exceptions.
Related Issues:
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.
Research direction
No source file or test is named in the issue. Reproduce the TypeScript 3.2 behavior using the provided Playground link and the class example, then inspect the compiler's handling of strictPropertyInitialization and static members. Done means both reads of the uninitialized static member produce compile errors without breaking valid inheritance or initialization semantics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100