Capítulo 8 de 36
Type['a'] pulls the type of a single property out of another type — the indexing key is itself a type, so it composes with unions, keyof, and typeof to slice out exactly the sub-type you need instead of redeclaring it.
type Age = Person["age"] extracts the type of the age property from Person.Person["age" | "name"] yields a union of both property types; Person[keyof Person] yields a union of every property's type.keyof, keeps the extraction in sync with the source type.number pulls an array/tuple's element type. Combined with typeof on an array literal, typeof MyArray[number] gives you the element type without writing it out by hand — and you can chain further: typeof MyArray[number]["age"].const variables: const key = "age"; type Age = Person[key] is an error because key is a value, not a type. Use a type key = "age" alias instead if you want a named, reusable index.const users = [{ name: "Alice", age: 15 }, { name: "Bob", age: 23 }];
type User = typeof users[number]; // { name: string; age: number }
type Age = typeof users[number]["age"]; // number
typeof + numeric indexed access, so the type always tracks the actual data shape.Type["prop"] (or Type[keyof Type]) over redeclaring a property's type elsewhere — it stays correct automatically when Type changes.typeof arrayLiteral[number] is the standard idiom for "the element type of this array, without a separate interface."type key = "age" if you want to name and reuse the index.