There is an ongoing effort to validate our API input stricter. As such we add more and more type checks for the options. One thing we still mainly lack is checking if there's a typo in an option. This could easily be done by checking if the passed in option is known or unknown. Obviously this would be semver-major, just as any other added type check.
Doing this for all APIs is a lot of work and can only be done iterative.
I would like to start with util.inspect but I don't really see any rush to do this. If we all agree on doing this everywhere throughout the code base, this could be a good first contribution and a good task for a code and learn event.
Refs: https://github.com/nodejs/node/pull/24971#issuecomment-448043734
// CC: @nodejs/tsc @joyeecheung
File tracking:
lib:
lib/internal:
lib/internal/bootstrap:
lib/internal/cluster:
lib/internal/console:
lib/internal/crypto:
lib/internal/dns:
lib/internal/fs:
lib/internal/http2:
lib/internal/modules/cjs:
lib/internal/modules/esm:
lib/internal/process:
lib/internal/repl:
lib/internal/streams:
lib/internal/test:
lib/internal/util:
lib/internal/vm:
If I understand this right, that means any unrelated object properties would cause exceptions to be thrown. If so, I'm very much -1 on that. We should only be caring about properties we expect. Forcing people to create new objects or delete existing properties just to prevent exceptions from node core isn't a good policy IMO.
@mscdex I don't really want this on all APIs. It is likely a case to case situation but a lot of our APIs only accept a specific set of options and adding others are silently ignored without any further effect. Those that are ignored are very likely typos and we are able to provide an improved user experience that way.
I would ask to first have a look at the existing API and the current implementation and to decide afterwards if it makes sense or not.

Yeah .. nah .. this is going to hurt a bit too much I think. I'd love if this had been done from the beginning, but Node was born in the jQuery era when we were all infatuated with how magical overloading and coercion could be. This ship has sailed and we're better off doing what we can to build guards around the implicit flexibility our API offers.
@rvagg if we do this API by API and check CITGM each time (which should be done for every semver-major) we should be able to limit the actual breakage to a pretty small amount. Don't you think so?
Nope, citgm is a teeny tiny snapshot of the ecosystem, and I doubt many of them have 100% coverage either. There's an absolute _ton_ of Node code that will never see the light of day, that we'll never get to test or grep, in organisations large and small that build critical applications on Node and make implicit assumptions about our API because _it just works_.
I wouldn't like to see this. I find it very useful to have an object with properties, and to pass it to multiple APIs, each of them picking up the properties they need.
The idea of doing it for only some APIs is even worse, IMO, than doing it for all. Our API's behaviour would become the subject of "guess which of these APIs is different" trivia quizs.
It's a bit like the object own-property debate... if I can do console.log(opts.shell); and see my shell, I should be able to do child_process.exec(opts) and have it respect the shell property. Its exactly what any javascript developer would expect.
Similarly, I don't think js devs expect APIs to explode because there are extra properties.
Can't people (optionally) use .ts annotations if for some reason they want this strict/fragile behaviour?
Due to the concerns mentioned here, I am going to close this. Thanks for your input!