Post AR17axzOwnuxlTC9tw by cassiozen@hachyderm.io
(DIR) More posts by cassiozen@hachyderm.io
(DIR) Post #AR17axzOwnuxlTC9tw by cassiozen@hachyderm.io
2022-12-27T01:30:05Z
1 likes, 0 repeats
#Typescript hint: Reuse your types! It’s a simple thing that pays off as your project grows; for example, if you have this type:```type Pokemon = { id: string, name: string, category: 'fire' | 'water' | 'electric', abilities: string[],}```You can access any nested type by using square brackets:```function find(category: Pokemon['category']) {// instead of using `category: string`// or repeating yourself// `category: 'fire'|'water'`…```
(DIR) Post #AR17b0WRWvXJcWfZgG by cassiozen@hachyderm.io
2022-12-27T01:35:47Z
0 likes, 0 repeats
If you’re new to Typescript, this is also a great way to get started with utility types. Want to update a Pokémon by passing only a partial object? ```function update(id: string, attributes: Optional<Pokemon>)```