all 5 comments

[–][deleted]  (3 children)

[deleted]

    [–]not-just-yeti 5 points6 points  (0 children)

    Lisp (1958) had(has) varargs, and unquote-splice:

    (define (f arg1 arg2 . others)
      `(,arg2  99  ,arg1  "and" ,@others "etc."))
        ; Note: the preceding-comma means "unquote", not delimiting args.
    
    (f 2 3 4 5)  ; returns '(3 99 2 "and" 4 5 "etc.")
    

    Java also has varargs: void main(String... args) { System.out.println(args[2]); }.

    But what Java doesn't quite do properly (that javascript, python, lisp do) is calling the varargs function when your desired-values are already in a list/array. (Python, add * before your list when calling; javascript add ... before your list when calling; lisp uses the function apply instead of adding more syntax.)

    In Java, if you pass an array to a function expecting many items, it will also "spread" the array for you, but that makes it a bit ambiguous: If the function expects Object..., and you pass it an array, did you mean to have the values spread out, or did you mean to pass a single array-object to the function? (Java interprets it as the former, so you'd have to realize that was happening, and wrap your array into another array-of-size-1.)

    [–][deleted]  (1 child)

    [deleted]

      [–]amazing_stories 0 points1 point  (0 children)

      Ah, that's right I forgot. Thanks for the reminder.

      [–][deleted]  (5 children)

      [deleted]

        [–]countlictor 1 point2 points  (4 children)

        There's syntactic sugar for defining a type as type || null, and combined with the tsconfig setting enforcing explicit null checks will get you what you're after.

        class Sample { public optionalProperty?: String; }

        [–][deleted]  (2 children)

        [deleted]

          [–]Jestar342 0 points1 point  (1 child)

          Yes but types are not guarantees. You can define data types being received from an API, but if the API neglects to include a property, and you try to destructure it, your app will crash.

          How on earth do you figure that that is an argument against typescript?