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 any typed values (e.g., anyValue.property)
Element access on any typed values (e.g., anyValue[0])
Using any typed values as computed property keys (e.g., obj[anyKey])
Construct a type with a set of properties K of type T
Record<string, number>;
declare const
const key:string
key:string;
const value:Record<string, number>
value[
const key:string
key];
declare const
const map:Map<string, number>
map:
interface Map<K, V>
Map<string, number>;
const map:Map<string, number>
map.
Map<string, number>.get(key: string): number |undefined
Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
@returns ― Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.
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 Flint disable comments and/or configuration file disables for those specific situations instead of completely disabling this rule.