Closed
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Playground Link
Repro Code
class Test {
public needsToBeDefined?: number;
private notReadonlyFoo?: number;
private notReadonlyBar?: number;
public testMethodFoo() {
if (!this.classPropertyGuard()) {
return;
}
this.notReadonlyFoo = 1;
}
public testMethodBar() {
if (!this.normalTypeGuard(this.needsToBeDefined)) {
return;
}
this.notReadonlyBar = 2;
}
private classPropertyGuard(): this is this & { needsToBeDefined: number } {
return this.needsToBeDefined !== undefined;
}
private normalTypeGuard(value: number | undefined): value is number {
return value !== undefined;
}
}
ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
rules: {
"@typescript-eslint/prefer-readonly": "error"
},
};
tsconfig
No response
Expected Result
I expected that private notReadonlyFoo?: number;
would not report any errors.
Actual Result
@typescript-eslint/prefer-readonly
error on the 4th line:
Member 'notReadonlyFoo' is never reassigned; mark it as `readonly`. 4:3 - 4:35
Additional Info
No response