Attempting to index an object using a key type other than string, number, or symbol.
TypeScript index signature parameters must be string, number, or symbol types. TS2538 is raised if you try to index an object using an object, union, or boolean parameter.
Using an enum instance or object reference to index a dictionary mapping instead of its string/numeric representation.
1interface UserRoleSettings {2 admin: boolean;3 user: boolean;4}5 6interface QueryParam {7 key: object; // object instead of string literal8}9 10const roles: UserRoleSettings = { admin: true, user: false };11const param: QueryParam = { key: { name: "admin" } };12 13// Error: TS2538: Type 'object' cannot be used as an index type14const isActive = roles[param.key];1interface UserRoleSettings {2 admin: boolean;3 user: boolean;4 [key: string]: boolean; // Fix 2: Add string index signature if keys are dynamic5}6 7interface QueryParam {8 key: 'admin' | 'user'; // Fix 1: Narrow key type to string literal union9}10 11const roles: UserRoleSettings = { admin: true, user: false };12const param: QueryParam = { key: "admin" };13 14const isActive = roles[param.key]; // Allowed!Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
param.key has the type object. Object structures cannot be used as JavaScript object lookup keys (they serialize to '[object Object]'), so TypeScript compiler flags this as an error.