"typeof keyof T" - Getting types of generic object's keys (Make keyof returning value instead of type) #24197
Closed
3 of 4 tasks
Labels
Question
An issue which isn't directly actionable in code
Search Terms
More or less similar issue: #23955
Suggestion
When using a
keyof
on a type, it returns a list of specific type of each key name.It could be useful to get the type of the value of each "keyof type".
Use Cases
For reflexion functions, it could be useful to manipulate and typecheck dynamically generic class and type.
Examples
Playground link:
https://www.typescriptlang.org/play/#src=interface%20IModel%20%7B%0D%0A%20%20%20%20id%3A%20number%3B%0D%0A%7D%0D%0A%0D%0Afunction%20foo%3CT%20extends%20IModel%3E(source%3A%20T%2C%20value%3A%20typeof%20keyof%20T%2C%20property%3A%20keyof%20T)%20%7B%0D%0A%20%20%20%20source%5Bproperty%5D%20%3D%20value%3B%0D%0A%7D%0D%0A%0D%0Afoo(%7B%0D%0A%20%20%20%20id%3A%201%2C%0D%0A%7D%2C%20'bar'%2C%20'id')%3B
In this case, I would like when I use the
foo()
function, to have the second parameter to provide dynamically the type of values set by the third parameter (in ctrl+space)Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: