Skip to content

Commit 639e015

Browse files
committed
Minor improvements
1 parent ee3fc70 commit 639e015

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

packages/plugins/eslint-plugin-react-x/src/rules/prefer-read-only-props.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,18 @@ function isTypeReadonlyLoose(services: ParserServicesWithTypeInformation, type:
7777
// @see https://github.com/Rel1cx/eslint-react/issues/1326
7878
function isClassOrInterfaceReadonlyLoose(checker: ts.TypeChecker, type: ts.Type) {
7979
const props = type.getProperties();
80-
const baseTypes = type.getBaseTypes() ?? [];
80+
const types = type.getBaseTypes() ?? [];
81+
// If there are no properties, consider it readonly
8182
if (props.length === 0) {
8283
return true;
8384
}
84-
if (baseTypes.length === 0) {
85-
return props.every((prop) => isPropertyReadonlyInType(type, prop.getEscapedName(), checker));
85+
// If there are no base types, check only the properties of the current type
86+
if (types.length === 0) {
87+
return props.every((p) => isPropertyReadonlyInType(type, p.getEscapedName(), checker));
8688
}
87-
return props.every((prop) => {
88-
if (isPropertyReadonlyInType(type, prop.getEscapedName(), checker)) return true;
89-
return baseTypes.every((type) => isPropertyReadonlyInType(type, prop.getEscapedName(), checker));
89+
// Check properties in the current type and all base types
90+
return props.every((p) => {
91+
if (isPropertyReadonlyInType(type, p.getEscapedName(), checker)) return true;
92+
return types.every((t) => isPropertyReadonlyInType(t, p.getEscapedName(), checker));
9093
});
9194
}

0 commit comments

Comments
 (0)