Index Access Types
Index Access
π¨βπΌ Index access types let you extract property types from other types using
bracket notation.
type Recipe = {
title: string
author: { name: string; rating: 1 | 2 | 3 | 4 | 5 }
}
type TitleType = Recipe['title'] // string
type AuthorType = Recipe['author'] // { name: string; rating: 1 | 2 | 3 | 4 | 5 }
type RatingType = Recipe['author']['rating'] // 1 | 2 | 3 | 4 | 5
π¨ Open
and:
- Extract nested property types from
ApiResponse(data,user,profile, and a single post) - Extract a type that covers both the
statusanderrorproperty types - Create a type for all possible value types of the nested user type
- Create and export these fixtures typed with your extracted types:
profile:{ avatar: 'https://example.com/avatar.jpg', bio: 'Hello!' }post:{ id: '1', title: 'Hello World', published: true }user:{ id: '1', name: 'Alice', profile: { avatar: 'url', bio: 'bio' } }
Completion check: those three exports match the fixtures above.