interface obj {
bar: string
}
function randomFunction() {
let foo: obj = { bar: "" }
foo.bar = "hip"
}
let snack: obj = { bar: "" }
snack.bar = "hop"
I get this warning from tslint:
Identifier 'foo' is never reassigned; use 'const' instead of 'let'. (prefer-const)
Funny though I don't get this warning in the second case with the variable snack
.
I can get rid of this warning (which clutters my console when transcompiling) with
/* tslint:disable: prefer-const */
I haven't found any bug report on the tslint project. Since I'm new to typescript I'm wondering: Do I something wrong here?
tslint is asking you to change let
to const
because the identifier foo
is not reassigned.
The error can be removed by instead writing const
:
const foo: obj = { bar: "" };
foo.bar = "hip";
Note that the const
modifier just means you can't reassign the identifier:
const foo = { bar: "" };
foo = { bar: "" }; // error
It doesn't make the object itself readonly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With