Simplified Way to Use Object in TypeScript
Problem
Have you ever had to face a situation when you need to call a variable’s name again, again and again?
Like this?
It takes time and also makes our code a bit messy.
Solution
This article might be one of the shortest article you would ever read 😄 but I think this is pretty much important to share to everyone here 😃
We could actually create an object in TypeScript to store all these properties from our object.
We can make something like this:
In TypeScript, it will automatically find the exact same name of the attributes in an object, therefore we could create a const variable containing those attributes that we only need.
But this method is only a personal preference on how we structure and create our codes.
We might still need to consider the space complexity in this method — I haven’t found this yet, will update once I found it.
Hope this article gives you some new insights 😃
Cheers,
Hengky Sanjaya