News for hackers. Stuff that matters.
Re:Problems with TypeScript by nocommentx on Wednesday January 15, 2020 @01:27PM (#22056888)
nope - the loss in velocity is not worth using it unless you're a massive team. TS is for Java programmers who are mad at Javascript for existing and don't know how it works well enough to grok overloading etc. plus you get a lot of the benefits of TS in an IDE like VSCode without actually having to use types at all. if you're a javascript native, typescript is constricting and eliminates one of the best parts of javascript - no types!!
Re:Problems with TypeScript by tmountain on Wednesday January 15, 2020 @01:38PM (#22057012)
I think this depends on where you are measuring costs in your codebase. If you're strictly looking at time to market on your first iteration, then you're right, types are going to require more of your team's time up front. If you look at the total lifespan of a "real project", then type safety is likely going to represent a cost savings regarding time your team spends on bug fixes, refactoring, and maintaining legacy portions of your app.

For context, I base the above sentiment on our team's last two years of effort in migrating key parts of our app to TypeScript (25 devs, ~500k lines of code). We've found that it has substantially reduced the number of defects that make it into production, and it has also reduced the number of round trips through QA. Clearly, this is only one data point, but hopefully it offers some perspective on why TS can be valuable in a codebase.

Re:Problems with TypeScript by nocommentx on Wednesday January 15, 2020 @01:45PM (#22057083)
sounds like its working for you, so i'm glad. you're about what i'd consider a big team / codebase. i can't recommend TS to people trying to create product from nothing. if your startup is doing well, you can hire someone to annotate your code w/ types later ;)
Re:Problems with TypeScript by gregplaysguitar on Wednesday January 15, 2020 @01:57PM (#22057220)
My experience is the opposite. One of the best things about TS is yhe refactoring experience - change a function signature for example and TS will tell you all the places you need to update. In a fast moving greenfields project with various requirements in flux, I’ve found this invaluable
Re:Problems with TypeScript by tmountain on Wednesday January 15, 2020 @02:10PM (#22057365)
I agree on this too. Oftentimes, we'll change a type and then just follow the errors in VSCode. It's a pretty great way to track down all the codepaths that are affected really quickly.
Re:Problems with TypeScript by jaywalk on Wednesday January 15, 2020 @01:34PM (#22056968)
I'm not quite sure why you consider "no types" to be one of the best parts of JavaScript, but TypeScript certainly doesn't require the use of types. It just makes the functionality available.
Re:Problems with TypeScript by jimbob45 on Wednesday January 15, 2020 @01:58PM (#22057246)
https://www.tutorialsteacher.com/typescript/function-overloa...

TS/JS don't allow for overloading the way that other languages do - it does not allow you to differentiate between functions via number of parameters, only types of parameters. If you try to differentiate based on number of parameters, it will simply use whichever definition of that function name it finds first.

Re:Problems with TypeScript by 52-6F-62 on Wednesday January 15, 2020 @04:29PM (#22058872)
That's not [entirely] my experience. Here's a quick example:

Declaration file style:

---

    // add.d.ts
    export declare function add(a: number, b: number): number;
    export declare function add(a: number, b: number, c: number): number;
    export declare function add(a: number, b: number, c: number, d: number): number;
---

    // add.js
    function add() {
     switch (arguments.length) {
      case 2:
       return arguments[0] + arguments[1];
      case 3:
       return arguments[0] + arguments[1] + arguments[2];
      case 4:
       return arguments[0] + arguments[1] + arguments[2] + arguments[3];
      default:
       throw new Error("Too few or too many arguments. Number of arguments: " + arguments.length);
     }
    }
    module.exports = { add };
---

    // adding.ts
    import { add } from "./add";
    
    console.log("4 + 4 =", add(4,4));
    console.log("4 + 4 + 4 =", add(4,4,4));
    console.log("4 + 4 + 4 + 4 =", add(4,4,4,4));

---

(Gist: https://gist.github.com/Robert-Fairley/98a2da3f0361e524f4e05...)

It will default to the first function name, but it definitely allows for overloading the number of parameters.

It's not perfect as you do still have to implement the function as it would need to be implemented for JS

Re:Problems with TypeScript by EdwardDiego on Wednesday January 15, 2020 @03:34PM (#22058185)
JavaScript has types. typeof {} === 'object'... Sure, they're very weakly held, which can be a lot of fun when you accidentally add a string and a number, but variables have types.
Re:Problems with TypeScript by sime2009 on Thursday January 16, 2020 @05:58AM (#22063408)
> no types!!

This might be news to you, but JS is full of types regardless of whether you document and automatically check them.

I prefer to document my types and have them properly checked, plus the IDE advantages.

Re:Problems with TypeScript by mixmastamyk on Wednesday January 15, 2020 @01:40PM (#22057030)
^large code base