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 }}
Repository navigation
Unexpectedly report error on correct code: 'field' is declared but its value is never read.(6133)'. #35153
Actual behavior: 'field' is declared but its value is never read.(6133).
Private member fieldcould be assigned by assigning to this[name] while name has the type 'field' (or any string literal union that contains 'field'). So I believe this error message is incorrect.
If I add readonly to this field, this[name] = value; will report another error: Cannot assign to 'field' because it is a read-only property.
The compiler leaves me no space for writing code like this.
Titian Cernicova-Dragomir (@dragomirtitian) the OP mentions Private member variable 'field' is never reassigned; mark it as 'readonly'. and that's definitely not a compiler error.
The error you get with noUnusedLocals ('field' is declared but its value is never read.) is correct, because the property is only written and never read.
Klaus Meinhardt (@ajafff) playground shows 'field' is declared but its value is never read.(6133), there is still an error. OK let me change the title of this issue.
changed the title [-]Unexpectedly report error on correct code: Private member variable 'field' is never reassigned; mark it as 'readonly'.[/-][+]Unexpectedly report error on correct code: 'field' is declared but its value is never read.(6133)'.[/+]on Nov 19, 2019
vczh Yes but as Klaus Meinhardt (@ajafff) pointed out, that error is actually correct in the context of noUnusedLocals. Add a read of the field and the error goes away as expected.
Activity
ajafff commentedon Nov 17, 2019
Are you sure this comes from the compiler? This looks more like a linter error to me.
dragomirtitian commentedon Nov 18, 2019
Klaus Meinhardt (@ajafff) It does come form the compiler if
noUnusedLocalsis used.Playground Link
ajafff commentedon Nov 18, 2019
Titian Cernicova-Dragomir (@dragomirtitian) the OP mentions
Private member variable 'field' is never reassigned; mark it as 'readonly'.and that's definitely not a compiler error.The error you get with
noUnusedLocals('field' is declared but its value is never read.) is correct, because the property is only written and never read.RyanCavanaugh commentedon Nov 18, 2019
One of these errors comes from tslint
vczh commentedon Nov 18, 2019
I don't think so, since https://www.typescriptlang.org/play/ gives me this error too. Unless it has tslint turned on.
ajafff commentedon Nov 19, 2019
vczh Look at the error message. It's different in the TypeScript playground
vczh commentedon Nov 19, 2019
Klaus Meinhardt (@ajafff) playground shows
'field' is declared but its value is never read.(6133), there is still an error. OK let me change the title of this issue.[-]Unexpectedly report error on correct code: Private member variable 'field' is never reassigned; mark it as 'readonly'.[/-][+]Unexpectedly report error on correct code: 'field' is declared but its value is never read.(6133)'.[/+]dragomirtitian commentedon Nov 19, 2019
vczh Yes but as Klaus Meinhardt (@ajafff) pointed out, that error is actually correct in the context of
noUnusedLocals. Add a read of the field and the error goes away as expected.Playground Link