Skip to content

Suggestion/feature request - enforce static properties/fields  #21976

@ORESoftware

Description

@ORESoftware

I added this question on SO:

is there a way to enforce static class properties? https://stackoverflow.com/questions/48813814/enforce-static-member-in-class-using-enum

It doesn't look like there is a way to do what I want to do, hence the feature request.

Code

declare enum Foods {
  CHERRY = 'CHERRY',
  LETTUCE = 'LETTUCE',
  JERKY = 'JERKY'
}

declare abstract class ForceFoods {
  static food : Foods
}

export class MyFoods implements ForceFoods {
  static food = Foods.CHERRY;  // if I omit this line, tsc will not complain
}

Expected behavior:
I was hoping tsc could enforce static properties to be defined

Actual behavior:
I don't currently believe tsc can enforce static properties

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions