3
nasuke
4y

Why the FUCK typescript exists? it solves NOTHING, it just adds more complexity to the code

Comments
  • 15
    It does the complete opposite of adding complexity.
  • 2
    @beegC0de How this:
    object: <Type> {}
    is simpler than just:
    object {}
  • 14
    @nasuke because now object is restricted to type Type, which hopefully provides reliable guarantees about it's functionally, so you don't have to bend over backwards to ensure those guarantees every time you use the object.
  • 5
    We use TS quite extensively in my company and it helps to catch many type and logical errors on transpile time.

    You can do this is js:

    function multi(a, b) {
    return a * b;
    }
    // you don't want this to be allowed...
    mult(1,'abc');

    In TS you can forbid this usage by using types:

    function mult( a:number, b:number) : number {
    return a * b;
    }

    // now this peoduces a type error
    mult(1,'abc');
  • 6
    Please provide your arguments as to why it makes things complex, also, have you ever worked with other type-safe languages like Java, c# or even lower?
  • 6
    Go learn Java then come back to JavaScript.

    This is why typescript exists, to bring backend type safety to a frontend language that doesn't have it.

    Outside of that, yes it's an added layer of JS that I don't use, as I am more then capable of looking up a function and seeing what it does and doesn't accept, and then not calling multi() with a string in it as @adifferent's example is doing calculations.
  • 2
    @alexbrooklyn yes, my first language was Java, I admit struggled at the beggining with Javascript, but when i understood how it worked, everything was easier.
    To me TS is like going back to Java again.
    My point with TS been adding complexity is that the code is harder to read.

    Edit: just like @C0D4 said, I found easier to just look at what a function accepts and work from there
  • 1
    @adifferent I mean... cant people just try a function and see if it fits their need?
  • 4
    @C0D4 I hope this will work out for you!

    For me and my company it's not so we switched to ts. I like the comfort and safety typescript provides when using it correctly..

    We develop a complex web frontend applications using react, xstate etc. and typescript provides a good (but not perfect) way to implement features faster, makes refactoring more safe and easygoing and enables a faster onboarding of new developers.
    It simply adds huge business value.

    We also get advanced intellisense and documentation of types on top.
  • 7
    @nasuke You're obviously thinking as a lone dev with his own source code.

    Try thinking of a large dev team where one dev modifies a function (refactoring and shit) without being aware that someone else had been using it in a certain way, and BAMM you have a runtime misbehaviour that will be hard to catch. With proper types, that would have been spotted at compile time.

    Means, NO debugging time (expensive), NO looking through the whole codebase (also expensive).
  • 3
    So that we can create a variable with ": any" type!
  • 0
    Typescript makes Javascript readable. Looking at JS source on github I have no idea what's going on since there's no way to know what data/type something returns. Typescript solves all of this.
Add Comment