What are index signatures in TypeScript?
Answer
Index signatures describe types that can have any number of properties with a consistent key and value type. Syntax: interface StringMap { [key: string]: string; } — any string key maps to a string value. Numeric index: interface NumberArray { [index: number]: string; }. Index signatures can be combined with specific properties, but specific property types must be assignable to the index signature value type: interface Config { [key: string]: string | number; version: number; }. Access: const val = map["anyKey"] — TypeScript knows val is string. noUncheckedIndexedAccess option in tsconfig makes TypeScript include undefined in the type of indexed access (since the key might not exist): val becomes string | undefined — safer but more verbose. Prefer Map for runtime key-value storage; use index signatures for describing existing JavaScript patterns. Record<string, V> is a cleaner alternative for typed dictionaries.