Skip to content

Commit

Permalink
fix(eslint-plugin): [prefer-readonly] correct issue with anonymus fun…
Browse files Browse the repository at this point in the history
…ctions #2590
  • Loading branch information
armano2 committed May 14, 2022
1 parent 1867728 commit fe8e6a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/eslint-plugin/src/rules/prefer-readonly.ts
Expand Up @@ -270,8 +270,12 @@ class ClassScope {
classNode: ts.ClassLikeDeclaration,
private readonly onlyInlineLambdas?: boolean,
) {
this.checker = checker;
this.classType = checker.getTypeAtLocation(classNode);
const classType = checker.getTypeAtLocation(classNode);
if (tsutils.isIntersectionType(classType)) {
this.classType = classType.types[0];
} else {
this.classType = classType;
}

for (const member of classNode.members) {
if (ts.isPropertyDeclaration(member)) {
Expand Down
13 changes: 13 additions & 0 deletions packages/eslint-plugin/tests/rules/prefer-readonly.test.ts
Expand Up @@ -292,6 +292,19 @@ class Foo {
},
{
code: `
function ClassWithName<TBase extends new (...args: any[]) => {}>(Base: TBase) {
return class extends Base {
private _name: string;
public test(value: string) {
this._name = value;
}
};
}
`,
},
{
code: `
class Foo {
private value: Record<string, number> = {};
Expand Down

0 comments on commit fe8e6a9

Please sign in to comment.