TypeScript Syntax and Type Operators
Index signature — dynamic property contract
An index signature describes values reachable through a class of property keys. A string signature also constrains explicitly declared string-named properties to compatible types. Number, symbol and template-pattern keys are available in suitable declarations. With noUncheckedIndexedAccess disabled, an unknown string key may be typed as number even if absent at runtime; enabling it adds undefined for unchecked access. Example output: "3". Tested in the strict TypeScript 5.8.3 / ES2022 baseline; the example is not a runtime type validator.
Formal Syntax & Structure
typescript syntaxtypescript
interface Counts { [key: string]: number; }Working Example
Example Snippettypescript
interface Counts { [key: string]: number; }const counts: Counts = { books: 3 };console.log(counts["books"]);