• @tgv
    link
    9
    edit-2
    1 year ago

    deleted by creator

    • @[email protected]
      link
      fedilink
      English
      171 year ago

      Type error unless there’s an implementation of + that specifies adding together and integer and a string.

      • @[email protected]
        link
        fedilink
        English
        101 year ago

        💯% accurate. funny how the typescript developer thinks this is some kind of “gotcha!”… like maybe just try a language besides typescript and find out for yourself 😆

      • @[email protected]
        link
        fedilink
        English
        01 year ago

        Exactly. Most languages I know of that allow this at all will coerce the “1” to an integer and give x = 2. They get away with this because they define the “+” operator as taking numbers only as arguments, so if you hand them x = x + "cheese" they’ll error out.

    • @[email protected]
      link
      fedilink
      1
      edit-2
      1 year ago

      I’m not sure if you’re being rhetorical or not, but “string|number” is definitely correct here. A computer could definitely figure this out, but typing is for the benefit of the coders more than the code itself. It’s basically functional documentation

      • @tgv
        link
        2
        edit-2
        1 year ago

        deleted by creator

        • @[email protected]
          link
          fedilink
          01 year ago

          Yeah that’s what I’m saying, I hate it when coworkers will assign everything as “any” just to avoid the scary red squigglies. Oh well I guess that’s what code reviews are for 🙃