You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My question is about the difference between { [key in string]: any } and Record<string, any> and their use cases.
Describe your question
I often have cases where I allow people to pass any plain JS object and will do something with that object, and pass back a new object based on the original, but with some changes.
馃 Question
My question is about the difference between
{ [key in string]: any }
andRecord<string, any>
and their use cases.Describe your question
I often have cases where I allow people to pass any plain JS object and will do something with that object, and pass back a new object based on the original, but with some changes.
some examples include:
Often I differentiate via JS between "plain objects" and "class instances" by looking at the prototype.
Now, currently in most cases I was just using a type like this for plain objects:
But since there were merge issues, you've explained before it's better to use:
so in many libraries I've been slowly replacing the types to that.
However, it seems many users use
Record<string, any>
as a "plain object" type...So considering my use cases above, what do you recommend I use?
Search tags, topics
#typescript #types #plain-objects #plain-object-type #object-type #record #faq #question
The text was updated successfully, but these errors were encountered: