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:
sorry :) I might have explained myself wrong.
I meant; What if you rename the
sizeproperty 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
countto the new type, could you do something like so:That way, you'd get size, caloriesPerServing and count as properties on the
Pizzatype?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
sizetocount, 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
Pizzatype...But if we renamed "size" to "count", as you suggested...
Then we would receive a type error at compile time on the
pepperoniPizzadeclaration 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! :)