3 ms·
If complex situations arise, they can slap `any` on it, at least it would be explicit, and marker to revisit in the future. Is there really that much legwork o
by tubthumper8 2y ago
If complex situations arise, they can slap `any` on it, at least it would be explicit, and marker to revisit in the future.
Is there really that much legwork otherwise? Adding ": string" to a function parameter assumes they know what a string is (which should already be the case), adding an object type assumes knowing what an object is, etc.
- shepherdjerred 2y agoThere is a big difference between typing your application (e.g. changing (arg) => {} to (arg: string): void => {}) and modeling your application in the type system. Simply adding types is usually not too difficult and it is still quite beneficial. It does eliminate certain kinds of bugs. Modeling your application in a type system means making invalid states unrepresentable and being as precise as possible. This is a lot more work, but again is eliminates more kinds of bugs that can occur. An example of this being complex: earlier this week I wrote a generic React component that allows users to define which columns of a table are sortable. I wanted to prevent any invalid configurations from being passed in. This is what it looks like: https://tinyurl.com/bdh6xbp6 https://tinyurl.com/bdh6xbp6 It's a bit complex but the compiler can guarantee that you're using the component correctly. This is more important and useful when it comes to business logic.