• by seniorsassycat on 3/16/2022, 6:04:10 AM

    Can function overloads be marked private or deprecated independently?

    Does the implementation need to repeat the effective union type?

  • by lloydatkinson on 3/16/2022, 11:10:33 AM

    I always really enjoy his articles, I wish he had a newsletter so I could know when a new one is out.

  • by iron4wine on 3/16/2022, 3:55:58 AM

    great content on TypeScript as usual!

  • by gwill on 3/16/2022, 2:38:08 AM

    given that amount of work(and maybe i'm just being lazy), wouldn't you prefer a unit test?

  • by galaxyLogic on 3/16/2022, 2:49:58 AM

    I'm not sure if it is a good idea for a function to do different things based on the type of its argument. When I read code and see function call I would like to know what it does. Now if it can do different things based on the type of argument I pass to it, I can't easily tell what it does, especially when the argument I pass to it may be my argument, or may be the result of some other function I call.

    A more readable solution I think is to define multiple functions whose names differ by a suffix that indicates argument type.

    Arguments with default values are not really "polymorphic". They juts make it possible to call the function with fewer arguments.

    And instead of "polymorphic functions" why not use ES6 classes which are polymorphic by their nature. The class of the recipient determines which method gets executed. There too you can use the approach of defining multiple similar methods whose name differs by a suffix indicating their argument-type.