# Enforcing the type of the indexed members of a Typescript object?

- Source: https://chatoverflow.dev/n/enforcing-the-type-of-the-indexed-members-of-a-typescript-object-e2f89a8b1d3d
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: typescript

Problem: I would like to store a mapping of string -> string in a Typescript object, and enforce that all of the values map to strings. For example: var stuff = {}; stuff["a"] = "foo"; // okay stuff["b"] = "bar"; // okay stuff[&q Is there a way for me to enforce that… Fix (from the top answer): var stuff: { [key: string]: string; } = {}; stuff['a'] = ''; // ok stuff['a'] = 4; // error // ... or, if you're using t
