[key: string]: T Index Signatures
Last updated: 2026-10-22
[key: string]: T Index Signatures
Index signatures describe objects with arbitrary keys but a uniform value type — dictionaries, counters, config maps. Written as [key: string]: T.
| Group | Type Composition |
|---|---|
| Kind | Syntax |
| Strict mode | Not required |
ℹ️ Info The editor transpiles TypeScript to JavaScript and runs it (no type checking); see each example's Output for type-check results.
📝 Syntax
const dict: { [key: string]: number } = {};
dict["a"] = 1;
// Equivalent utility-type spelling
const same: Record<string, number> = {};
⚙️ Parameters
| [key: string] | Key type must be string, number, symbol or a union; the key name is arbitrary |
|---|---|
| [i: number] | [i: number]: T describes index-based access; the number index type must be a subtype of the string index type |
Returns:None — index signatures are type-level only and produce no runtime code.
▶ Example
Edit the code below and click Try it to see the transpiled result:
Output:
180 0
(Runtime output after transpilation; scores["Bob"] types as number without error — index signatures declare every key exists)
💡 Notes
ℹ️ Info Record<string, number> means the same as { [key: string]: number }; the utility form is more common.
⚠️ Note Index signatures make every key legal: scores["Bob"] passes even under strict, so typos slip through. For a finite key set use Record<"a" | "b", T> or mapped types.
💡 Tip For mixed values use a union — { [key: string]: string | number } — and narrow after reading.
🏷️ Related Type Composition
💡 Related cases
More cases coming soon.
📚 Related tutorials
❓ FAQ
Q Index signature vs Record<K, V>?
A Equivalent in power — Record is an index signature implemented via mapped types. Record is terser and can also pin an exact key union.
Q Why does accessing a missing key not error?
A That is the semantics: every string key exists with type T. To catch typos, pin keys with Record<"a" | "b", T> or enable noUncheckedIndexedAccess.
Q Can number and string index signatures coexist?
A Yes, but the number index value type must be a subtype of the string one (JS numeric keys become string keys under the hood).