Loading topic
keyof, typeof in a type position, and T[K]) are tools for moving information between those8 min readkeyof operator: what it produces, what it counts as a key, and where it goes wrong. It assumes you know TypeScript interfaces, type aliases, and union types, and that you have seen generic type parameters. The previous chapter separated type positions from value positions. 5 min readkeyof does on an object type and what typeof does in a type position, both covered earlier in this tutorial. It also assumes you can read basic generics. Here you combine the two operators so that a plain JavaScript object becomes the single source of truth for6 min readkeyof and typeof. You will use keyof and typeof here, but you don't need the l5 min readkeyof, typeof, and indexed access types. Those operators can only read the types that already exist. This chapter covers as const, which controls how precise those types are. It assumes you know interfaces, type aliases, union types, and basic generics. It also assumes6 min readkeyof, typeof in type positions, and indexed access types (T[K]). You should also be comfortable with as const and with generic constraints. Here you will use one specific indexed access, T[number]. It turns an array or tuple type 5 min readkeyof T and indexed access types like T[K] from the earlier chapters. Here they combine into one pattern: a generic function that accepts only keys that exist on an ob5 min readkeyof T (the union of an object type's keys) and T[K] (the type of one property) from earlier chapters. A mapped type combines those two pieces to build a new object type from an6 min readkeyof returns for such types, why the result surprises people, and which generic helpers stop working as expected.5 min readkeyof behaves when the type it receives is a union, an intersection, or has optional properties. These cases often give results that look reversed at first. It assumes you know keyof on a plain object type, indexed access types such as T["key"], and basic mapped types. 5 min read