I think I understand - so you're suggesting if we renamed size to count, this would cause issues?
size
count
Type-checking would catch that (the beauty of TypeScript!). In the below example, we pick the two properties to create the new Pizza type...
Pizza
type Pizza = Pick<Consumable, "size" | "caloriesPerServing">; const pepperoniPizza: Pizza = { size: "large", caloriesPerServing: 500 }
But if we renamed "size" to "count", as you suggested...
type Pizza = Pick<Consumable, "size" | "caloriesPerServing">; const pepperoniPizza: Pizza = { count: "large", caloriesPerServing: 500 }
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.
pepperoniPizza
We could then perform the changes we require on our type:
type Pizza = Pick<Consumable, "count" | "caloriesPerServing">;
...which would resolve the issue.
Did that make sense? Hope that answers your question!
Did that make sense?
yes it does
Hope that answers your question!!
thanks!
Ah, that's great to hear. Sorry I misunderstood you initially! :)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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! :)