Hey Vetras! It doesn't actually rename those properties - rather, it plucks them from the original interface and creates a new type consisting of the picked properties. So in that case, the resolved Pizza type would end up looking like:
sorry :) I might have explained myself wrong.
I meant; What if you rename the size property to count, for example.
Would the Pizza be renamed to pizza.count?
Can the IDE pick that up? (pun intended 😎)
Then we would receive a type error at compile time on the pepperoniPizza declaration line, as the object's shape (Pizza) does not have the property count.
We could then perform the changes we require on our type:
Hey Vetras! It doesn't actually rename those properties - rather, it plucks them from the original interface and creates a new type consisting of the picked properties. So in that case, the resolved
Pizza
type would end up looking like:Hope that makes sense :)
sorry :) I might have explained myself wrong.
I meant; What if you rename the
size
property tocount
, for example.Would the Pizza be renamed to
pizza.count
?Can the IDE pick that up? (pun intended 😎)
I guess if you wanted to add
count
to the new type, could you do something like so:That way, you'd get size, caloriesPerServing and count as properties on the
Pizza
type?Unsure if that's what you're asking, but I hope that helps!
true. that is not what I meant. I mean renaming the original property named "size" to the new name "count" (as an example).
Refactoring is a big part of writing maintainable software and renaming is a basic corner stone of refactoring.
Hence my question.
I think I understand - so you're suggesting if we renamed
size
tocount
, this would cause issues?Type-checking would catch that (the beauty of TypeScript!). In the below example, we pick the two properties to create the new
Pizza
type...But if we renamed "size" to "count", as you suggested...
Then we would receive a type error at compile time on the
pepperoniPizza
declaration line, as the object's shape (Pizza
) does not have the propertycount
.We could then perform the changes we require on our type:
...which would resolve the issue.
Did that make sense? Hope that answers your question!
yes it does
yes it does
thanks!
Ah, that's great to hear. Sorry I misunderstood you initially! :)