Skip to content

strictPropertyInitialization does not require initializer #52259

Closed
@arv

Description

@arv

Bug Report

If I have strictPropertyInitialization set to true in tsconfig.json I expect that it would be an error if there is no initializer for a property.

🔎 Search Terms

strictPropertyInitialization
undefined
initializer

🕗 Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground link with relevant code

💻 Code

class C {
  // @ts-expect-error Missing initializer
  x: number | undefined;
}

🙁 Actual behavior

No compile error

🙂 Expected behavior

I expect there to be a compile error because instances of this class will not have an x property.

Always initializing properties in a fixed order is important to ensure all instances end up with the sam hidden class in a lot of JS VMs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions