It is a really good feature coming with TypeScript 5.0. We could infer type of object as general as shown in line 8 in below code, so, to infer more-specific type, we had to add as const
as shown in line 11.
![](https://kenanhancer.com/wp-content/uploads/2023/05/Screenshot-2023-05-23-at-11.53.54-1024x222.png)
TypeScript 5.0 makes it easier with adding const
in front of type parameter declaration in line 13 in below code.
![](https://kenanhancer.com/wp-content/uploads/2023/05/Screenshot-2023-05-18-at-06.56.04-1024x225.png)
Use case
Assume that Person
type has hobbies
, and i just want to infer passed values from hobbies
field.
![](https://kenanhancer.com/wp-content/uploads/2023/05/Screenshot-2023-05-23-at-12.12.15-1024x417.png)