Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
I'm pointing out a "gotcha" in relation to @ryanmcdermott's comment at the end of #199 in regards to objects as function argument configs.
I agree wholeheartedly with points 1-3 and they have greatly improved some of the readability and usability of some of my personal projects. However, I build an Angular6/Typescript project at work and recently had an opportunity to leverage this approach and here's what I found.
Three years since that comment has apparently yielded some concrete ammunition against your thesis on this approach in virtually all situations in Typescript.
This will cause Typescript to throw a compilation error:
error TS2345: Argument of type '{ width: 123 }' is not assignable to parameter of type '{ width: any; color: any; }'.as this appears to violate Typescripts deterministic validation of your code.The work around to this in Typescript requires at least an
interfaceof the methods argument object signature. As a JS purist, I hate this because it obfuscates your method signature away from your implementation in the code, but if you're using a sophisticated enough IDE then technically intellisense/autocomplete would handle the issue for you and DocBlock comments could easily handle explaining the situation, but it just feels bad to me :PIt's still not great in my opinion compared to the inherit flexibility in native JS, but something I thought worth mentioning/discussing because this apparently is a hell of an exception to the rule.
Cheers!