You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
There is an argument that using const instead of let makes code more readable, since you can be sure at a glance that a variable will not change it's value. (See prefer-const)
Unfortunately, in TypeScript (or JavaScript) there is no way to declare that a particular function parameter should be const (they are all implicitly let).
For example, the following function modifies the x parameter:
I imagine that a lot of projects would be happy to completely ban all such usages in their code base: all function parameters would behave as if they were const. I believe that this can be implemented as a tslint rule, and I suggest that such a rule be added =]
The text was updated successfully, but these errors were encountered:
IMO such a rule makes sense. The implementation should not be too different from prefer-const. Maybe we can extract some of the logic into a reusable class or function.
Until it is implemented in tslint core, you can use a third party rule: https://github.com/vrsource/vrsource-tslint-rules#no-param-reassign
Just one question if we want to treat destructured parameters as real parameters? Would be best to make it configurable, I guess.
functionfoo(bar: number){}// this is a parameterfunctionfoo([bar,baz]: number[]){}// technically these are local variables ... do we want to treat them as parameter?
There is an argument that using
const
instead oflet
makes code more readable, since you can be sure at a glance that a variable will not change it's value. (See prefer-const)Unfortunately, in TypeScript (or JavaScript) there is no way to declare that a particular function parameter should be
const
(they are all implicitlylet
).For example, the following function modifies the
x
parameter:I imagine that a lot of projects would be happy to completely ban all such usages in their code base: all function parameters would behave as if they were
const
. I believe that this can be implemented as a tslint rule, and I suggest that such a rule be added =]The text was updated successfully, but these errors were encountered: