close

no-unsafe-member-access

Added in v0.1.4

Configuration

PresetConfigured Value
✅ ts.configs.recommendedTypeChecked"error"
✅ ts.configs.strictTypeChecked"error"
rslint.config.ts
import { defineConfig, ts } from '@rslint/core';

export default defineConfig([
  ts.configs.recommended,
  {
    rules: {
      '@typescript-eslint/no-unsafe-member-access': 'error',
    },
  },
]);

Rule Details

Disallow member access on a value with type any.

Accessing a member (property or element) on an any-typed value is unsafe because the result will also be typed as any, propagating the lack of type safety. This rule flags both dot-notation property access and bracket-notation element access on any-typed values, as well as computed member access where the index expression is typed as any.

Examples of incorrect code for this rule:

declare const anyVal: any;
anyVal.foo;
anyVal['bar'];
anyVal[0];

declare const key: any;
declare const obj: { [k: string]: number };
obj[key];

Examples of correct code for this rule:

declare const obj: { foo: string };
obj.foo;

declare const arr: string[];
arr[0];

declare const key: string;
declare const map: { [k: string]: number };
map[key];

Optional chaining on any remains unsafe by default. Set allowOptionalChaining to true to allow only the access link containing ?.:

{
  "@typescript-eslint/no-unsafe-member-access": [
    "error",
    { "allowOptionalChaining": true }
  ]
}
declare const value: any;
const result: unknown = value?.property;

Original Documentation