The "doStuff" team at your company created a function for you to use
and then you diligently call it in your code like this
all fine and good
The doStuff
team says, well, it's not really a true "z coordinate"....it's
more of a "z-index" so they change the function definition to be
Since zIndex
is optional, typescript will not warn you about zIndex
not
being supplied by your existing code. Typescript is also not bothered that you
have this "rider" variable z
that "does nothing" in this case.
Here is the funny thing:
Typescript DOES NOT catch this issue when you pass it via this separately created "obj" variable.
Typescript DOES(!!!) catch this issue when you pass it directly to the function (as an "object literal")
Demo playground
I am certainly not the only person to come across this "topic/issue", and people often come across it in different contexts.
My particular take away is to "be careful when you rename optional props". Of course, changing any API comes with risks, but this one particularly :)
Typescript Deep Dive - "Freshness"
https://basarat.gitbook.io/typescript/type-system/freshness
This post was given lots of downvotes in /r/typescript and sarcasm that "no duh, breaking changes are breaking".
However, some helpful comments were made also. Read on https://www.reddit.com/r/typescript/comments/1fk1rqe/be_careful_when_you_rename_an_optional_prop_in/
I think maybe people are distracted that I posited this as the "doStuff team" vs "you", but keep in mind this could just be your left brain vs right brain in an actively developed codebase