-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[no-parameter-properties] Support enforcing the inverse #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I agree, it's much cleaner with parameter properties. |
I've always used them as well. What are y'all's thoughts about the argument for introducing the rule in the first place?
It sounds like the argument is that it confuses people who don't know TypeScript? A bit of a weak argument, if you ask me. |
@jedmao - Some people don't like parameter properties. As with all rules, it's there to enforce a stylistic/personal preference for code - enforcing consistent code throughout a codebase. We should probably look at re-evaluating all of our |
Copying a relevant code snippet from palantir/tslint#2638 (comment): FWIW, parameter properties are quite nice when using libraries such as Inversify: @injectable()
class Ninja implements Warrior {
private _katana: Weapon;
private _shuriken: ThrowableWeapon;
public constructor(
@inject(TYPES.Weapon) katana: Weapon,
@inject(TYPES.ThrowableWeapon) shuriken: ThrowableWeapon
) {
this._katana = katana;
this._shuriken = shuriken;
}
public fight() { return this._katana.hit(); };
public sneak() { return this._shuriken.throw(); };
} ..compared to... @injectable()
class Ninja implements Warrior {
public constructor(
@inject(TYPES.Weapon)
private readonly katana: Weapon,
@inject(TYPES.ThrowableWeapon)
private readonly shuriken: ThrowableWeapon,
) { }
public fight() { return this.katana.hit(); };
public sneak() { return this.shuriken.throw(); };
} |
Co-authored-by: o.drapeza <[email protected]>
The
no-parameter-properties
rule enforces not using parameter properties, but I would like to enforce use of parameter properties whenever possible. I actually like the shorthand.I would suggest renaming the rule to
parameter-properties
(without theno-
prefix) and support enforcing both use and non-use of parameter properties.Relevant TSLint issue: palantir/tslint#2638
The text was updated successfully, but these errors were encountered: