Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 1.13 KB

explicit-member-accessibility.md

File metadata and controls

42 lines (29 loc) · 1.13 KB

Require explicit accessibility modifiers on class properties and methods (explicit-member-accessibility)

Leaving off accessibility modifier and making everything public can make your interface hard to use by others. If you make all internal pieces private or protected, your interface will be easier to use.

Rule Details

This rule aims to make code more readable and explicit about who can use which properties.

The following patterns are considered warnings:

class Animal {
  name: string; // No accessibility modifier
  getName(): string {} // No accessibility modifier
}

The following patterns are not warnings:

class Animal {
  private name: string; // explicit accessibility modifier
  public getName(): string {} // explicit accessibility modifier
}

When Not To Use It

If you think defaulting to public is a good default, then you will not need this rule.

Further Reading

Compatibility