Skip to content

Enforce definite initialization of static members #27899

@bcherny

Description

@bcherny

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.

Playground Link

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions