anyMemberAccess
Reports member access on a value with type
any.
✅ This rule is included in the ts logical preset.
Accessing a member of a value typed as any creates a potential type safety hole and source of bugs.
TypeScript cannot verify that the member exists or what type it has.
This rule disallows member access on any variable that is typed as any.
This includes:
- Property access on
anytyped values (e.g.,anyValue.property) - Element access on
anytyped values (e.g.,anyValue[0]) - Using
anytyped values as computed property keys (e.g.,obj[anyKey])
Examples
Section titled “Examples”declare const value: any;value.property;declare const value: any;value["property"];declare const value: any;value.a.b.c;declare const obj: { a: number };declare const key: any;obj[key];declare const value: { property: string };value.property;declare const value: string[];value[0];declare const value: Record<string, number>;declare const key: string;value[key];declare const map: Map<string, number>;map.get("key");Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your codebase has many existing any values or areas of unsafe code, enabling this rule may be challenging.
It may be more practical to defer enabling this rule until type safety has been improved in those areas.
You might consider using lint disable comments for specific situations instead of completely disabling this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.