• Unlike traditional types such as string, number, or even JavaScript’s dangerously permissive any, an ambiguous variable can contain any value, several values, or no value at all, depending on execution context, compiler mood, and whether anyone is currently debugging it.

      It’s different than loosely typed vars, which are not at all exclusive to Javascript

      • bitfucker@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        13 days ago

        “any value, several, or no value”. Any in JS is literally that tho, sans “Never” iirc

        Edit: oops, I was wrong. Any MAY be a never. Typescript allows it

  • unalivejoy@piefed.social
    link
    fedilink
    English
    arrow-up
    2
    ·
    13 days ago

    JavaScript’s dangerously permissive any

    Excuse me? JavaScript doesn’t have any. They’re thinking of TypeScript’s any.

    • Karjalan@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      13 days ago

      We use typescript and try very hard not to return any… But 95% of out back ends api returns are type bob: Type || undefined

      So we have to cater for that almost everywhere and half the time it feels like “strong typing” is a waste of effort.

      But I still prefer the relative certainty of typescript

      • kkj@lemmy.dbzer0.com
        link
        fedilink
        English
        arrow-up
        1
        ·
        13 days ago

        So, an equivalent to C#'s Type? or Python’s Optional[Type]? That’s still a lot better than nothing. You aren’t going to get an array when you asked for a float, for example.

        • Zarobi@aussie.zone
          link
          fedilink
          English
          arrow-up
          1
          ·
          13 days ago

          You still might. Typescript is just a fancy linter, it doesn’t actually stop anything from happening. If a backend API changes to give you an array, you will get an array, and it will be a disaster

      • wucking_feardo@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        13 days ago

        I don’t know shit about your codebase. But it sounds like you aren’t abstracting your API calls property. Ideally you have an API Client that consumes those blobs and converts them to some generically typed return value.

        On top of that you have your actual API, which accepts actions and returns actual objects/collections, or just fucking fails and bubbles up as a generic error because something’s gone fucking wrong.

        • Karjalan@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          13 days ago

          It’s mainly because, for the industry we’re in, we’re not very big. So we have small teams with few devs…

          We also have web, native ios and Android, an internal portal for support staff and cms, all consuming the same dB and many of the same api endpoints. This means they can be undefined for one, but not the other.

          So even though on Web you will always have join_table_id… It could be undefined (for another platform)