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.
TypeScript 5.0 makes it easier with adding const
in front of type parameter declaration in line 13 in below code.
Use case
Assume that Person
type has hobbies
, and i just want to infer passed values from hobbies
field.