Naming convention for class properties in TypeScript

前端 未结 3 2157
花落未央
花落未央 2020-12-29 23:06

According to the offical style guide you should

Avoid prefixing private properties and methods with an underscore.

As I come f

3条回答
  •  被撕碎了的回忆
    2020-12-29 23:54

    If the question is strictly :

    Is there a way to follow the [typeScript] style guide and also use the get/set properties of TypeScript?

    Where the TypeScript Style Guide says :

    Avoid prefixing private properties and methods with an underscore.

    Then you can use the $ (dollar sign) instead of the _ (underscore) to prefix your private fields. In this way you both get rid of the [ts] Duplicate identifier 'blablabla' error while still respecting the TypeScript Style Guide.

    In addition, but it is just my opinion, the .$combination is more readable than the ._combination.

提交回复
热议问题