Is it possible to loop over a type definition?
A simple type like:
interface Budget {
bills: number;
transportation: number;
}
And then something like:
Object.keys(Budget).map((item) => etc...)
Obviously the above doesn't work, is something like this possible? So that I don't have to create an object of type Budget whenever I want to utilize built in functions?
The answer is no. Types are removed by the transpiler before runtime. In your case, the Budget
reference will be undefined as no object named Budget
exists in the transpiled code which is actually executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With