Allow access to labels in array types and parameter names in functions #55736
Labels
Declined
The issue was declined as something which matches the TypeScript vision
Suggestion
An idea for TypeScript
π Search Terms
array label name typeof labelof
β Viability Checklist
β Suggestion
Similarly:
On its own, the above type signature doesn't do much. But using other advanced type generics, you can get keys of functions (or labels of arrays), the optionality of values, the combined types, etc.
π Motivating Example
Within the comments of this issue, describing the array label idea (which was implemented, there were a few questions about retrieving said labels.
I have a use case for wanting access to the labels as keys, specifically for integration with Typia, in which function signatures could be mapped as named arguments in abstracted function calls. (That is, a runtime check to see if the arguments I wish to pass into the function matches the function signature, in an environment where TypeScript is not available to the downstream function for a compile-time check.)
π» Use Cases
What do you want to use this for?
Emitting runtime labels of functions.
What shortcomings exist with current approaches?
There are no current approaches to do this, as far as I know. Array labels and function parameters are hidden from the type system
What workarounds are you using in the meantime?
The only workaround I can think of is to explicitly and verbosely duplicate all the label names in a function in an external array?
The text was updated successfully, but these errors were encountered: