News for hackers. Stuff that matters.
Re:Cold Showers by esperent on Saturday June 18, 2022 @07:07PM (#31794631)
What about

    addItemsToCart(items)
Vs

    Type ItemCode: string;
    Type ItemDetails = {...};
 

 
    addItemsToCart(items:ItemCode[])
or, for a slightly different implementation:

    addItemsToCart(items:Record<ItemCode, ItemDetails>)


If you only use trivial examples, types seem silly. But in real examples they become more useful. In this case looking at the function signature give you immediate information about the implementation that is missing from the untyped version.

EDIT: please excuse formatting, I'm on mobile and cannot get it to add spaces before the last code block

There are no comments on this comment yet.