Typescript madness

Typescript madness

Schizophrenic Conspiracy Theorist Shirt $21.68

Homeless People Are Sexy Shirt $21.68

Schizophrenic Conspiracy Theorist Shirt $21.68

  1. 4 weeks ago
    Anonymous
  2. 4 weeks ago
    Anonymous

    It was inevitable

    • 4 weeks ago
      Anonymous

      To be fair, he found a better solution lol

      • 4 weeks ago
        Anonymous

        is that context free grammar inside typescript kek

      • 4 weeks ago
        Anonymous

        so whats happening here? Can TS define types over number ranges use some kind of enumstring as a type and then match over it to assign a value? So A is just checking whether it is of those types and then returns a bool?

        • 4 weeks ago
          Anonymous

          Looks like string types.
          in typescript you can do do stuff like
          type Size = "small" | "medium" | "large"

          Its saying "this type can only contain these strings"
          It makes up for javascript's lack of enums

          • 4 weeks ago
            Anonymous

            >It makes up for javascript's lack of enums

          • 4 weeks ago
            Anonymous

            you can just make an object literal.
            const Status = { INITIAL: 'initial', ... }
            why would an interpreted dynamic weakly typed language need to differentiate between the two? why do people keep point this out like some kind of flaw? do people just parrot each other without thinking at all? Enums would be pointless in JS.

          • 3 weeks ago
            Anonymous

            You wouldn't understand but for the rest of the people the reason you want real enums is to get compile time enforcement of constraints, instead of run time enforcement which would create a bad user experience.
            But scriptlets literally do not understand the concept and will forever use bulky run time mechanisms to create a bad user experience because they hate everyone.

          • 3 weeks ago
            Anonymous

            Yep. JavaScript "enums" like

            >It makes up for javascript's lack of enums

            are not actually type safe.

            Once again IQfy demonstrates its its ignorance when discussing anything web related.

          • 3 weeks ago
            Anonymous

            >run time enforcement which would create a bad user experience
            what do you mean by this? How would an object literal like

            >It makes up for javascript's lack of enums

            cause a bad user experience?

          • 3 weeks ago
            Anonymous

            Because when you do Status.MY_ASS, you will get no warning at compile time but it will be undefined at runtime, and you'll be left scratching your head trying to understand why your program isn't doing what you want it to.

          • 3 weeks ago
            Anonymous

            Ahh, you meant user as the developer, not the end user. Sorry for the confusion.
            Still, most people would get the field through autocomplete rather than manually typing them. I think that's still miles ahead than using raw strings, and a reasonable middle ground if you're using a dynamic language. As a bonus, printing it in the console will show a matching name rather than an integer like a C-style enum would.

          • 3 weeks ago
            Anonymous

            What I've done is use "const enum" in Typescript, pic related, and if I need name strings at runtime I just add an object that maps the values to strings. A const enum gets converted to raw numbers and there is no actual enum object at runtime so there is no overhead which is the reason I use it.

          • 3 weeks ago
            Anonymous

            >there is no actual enum object at runtime so there is no overhead
            what overhead would there be at runtime? There are very, very few circumstances where an object property look up is a bottleneck.

  3. 4 weeks ago
    Anonymous

    I warned you all

    • 3 weeks ago
      Anonymous

      To be fair, he found a better solution lol

      It was inevitable

      Great, now godbolt it

  4. 4 weeks ago
    Anonymous

    >webdevs managed to ruin static typing
    marvelous

    • 4 weeks ago
      Anonymous

      >filtered by generics

      • 4 weeks ago
        Anonymous

        >filtered by memory

  5. 4 weeks ago
    Anonymous

    Explain?

    • 4 weeks ago
      Anonymous

      Explain!

    • 4 weeks ago
      Anonymous

      Booleanish is a type used in vue templates, where you can either use a boolean, or a string literal "true" or "false". OP is too moronic to know that list of possible values doesn't include numbers, and is blaming typescript for his lack of understanding.

      • 4 weeks ago
        Anonymous

        >you can either use a boolean, or a string literal "true" or "false"
        Imagine defending this

        • 4 weeks ago
          Anonymous

          That's javascript's fault, not typescript's.

        • 4 weeks ago
          Anonymous

          >Imagine defending this
          homie do you have any reading comprehension? he's not saying that a boolean | "true | "false" type is good, he's saying that OP is being silly.

          >It makes up for javascript's lack of enums

          that approach would require you to explicitly create an object for every list of acceptable constant you might use anywhere.
          Using the approach from

          Looks like string types.
          in typescript you can do do stuff like
          type Size = "small" | "medium" | "large"

          Its saying "this type can only contain these strings"
          It makes up for javascript's lack of enums

          , you can have the acceptable input inside the function definition:

          const setEncodingPreset = (preset:'high' | 'low') => { //... }

          • 3 weeks ago
            Anonymous

            >Using the approach from

            Looks like string types.


            in typescript you can do do stuff like
            type Size = "small" | "medium" | "large"

            Its saying "this type can only contain these strings"
            It makes up for javascript's lack of enums, you can have the acceptable input inside the function definition:
            Is that supposed to be a good thing? Having each function define the type of its own parameters, instead of declaring an universal well-thought enum, that functions have to adhere to? Sounds to me like a ticking bomb

          • 3 weeks ago
            Anonymous

            >Having each function define the type of its own parameters, instead of declaring an universal well-thought enum, that functions have to adhere to?
            like the answer to almost everything in engineering, it depends. If it's only used in a single place, you can keep complexity down and export one less type from your module, which IMO is worth it. But that type may be something important to the domain you're dealing with, so it may make more sense to name it. No silver bullet etc etc.

  6. 4 weeks ago
    Anonymous

    >Booleanish
    Not a standard type. Blame the monkeys who made whatever moronic library you're using.

  7. 4 weeks ago
    Anonymous

    Eh, ad hoc algebraic types are kinda neat.

  8. 4 weeks ago
    Anonymous

    Typescript seemed cool at fist but now it seems like a bloated mess.

  9. 3 weeks ago
    Anonymous

    wait until you see what type a checkbox emits kek

  10. 3 weeks ago
    Anonymous

    >everyone ITT getting filtered because they don't know the problem space the types are solving nor the syntax

    Lol

  11. 3 weeks ago
    Anonymous

    TypeScript features get a little bonkers but IME they're really useful for adding typechecking to existing code without throwing out the whole design

Your email address will not be published. Required fields are marked *