News for hackers. Stuff that matters.
Re:Convert React JavaScript Code to TypeScript with Proper T... by seekbeak on Tuesday January 16, 2018 @01:49PM (#16160924)
It's such a no brainer after you use it for a while, and the time savings after the fact far make up for the initial learning curve.

Just do a small project to muck around with first. Maybe something small that nobody has thought of, like a to-do list?

Re:Convert React JavaScript Code to TypeScript with Proper T... by 52-6F-62 on Tuesday January 16, 2018 @02:15PM (#16161258)
Can also confirm. Recently a convert and it's a breeze. It makes for more maintainable code, ultimately, and has even cleaned up some of my poorer JS habits.

Also, for those who get caught up rewriting types for existing libraries, I recommend you check this library first:

https://github.com/DefinitelyTyped/DefinitelyTyped

Re:Convert React JavaScript Code to TypeScript with Proper T... by evanm on Tuesday January 16, 2018 @02:08PM (#16161166)
> You can take an incremental approach and add type annotations as you need them

Most definitely. We've added type safety to new features in our legacy codebase. It's very seamless.

Re:Convert React JavaScript Code to TypeScript with Proper T... by gedy on Tuesday January 16, 2018 @02:07PM (#16161153)
> and the time savings after the fact

Could you elaborate how? I used to heavily use typed languages, but after moving to JS 5 years ago, I don't miss types.

Re:Convert React JavaScript Code to TypeScript with Proper T... by ggregoire on Tuesday January 16, 2018 @02:26PM (#16161381)
- Get autocompletion for everything: object properties (eg. user.[firstname, lastname, etc]), type-specific methods (eg. thisIsAStringButYourEditorCantKnow.[list of string methods provided by your editor since you told him it's a string]), etc

- Detect bugs and errors early, removes some kind of bugs (eg. typo errors: user.fisrtname, your editor will tell you fisrtname is not a property of user)

- Help to refactor (eg. 'Rename Symbol' in VSC can't work on everything if your code isn't typed, eg. (X => X.someProperty), someProperty isn't renamable automatically since your editor doesn't know what's X)

- Reduce extra error handling (eg. if (a === undefined || b === undefined || a is not a number || b is not a number) throw new Error(...))

- Reduce extra unit tests (eg. expect(add(5, undefined)).toThrowAnError(); expect(add(5, 'foo')).toThrowAnError();)

- etc...

Re:Convert React JavaScript Code to TypeScript with Proper T... by Waterluvian on Tuesday January 16, 2018 @02:09PM (#16161180)
The one time I think, "oof I really would have liked types here" is when I begin digging deep through a stack of calls to understand what values I should expect and are valid. This hurt me in Python too until I began using type hinting, which in my opinion is the best of both worlds: documenting types but not forcefully enforcing typing.
Re:Convert React JavaScript Code to TypeScript with Proper T... by hota_mazi on Tuesday January 16, 2018 @07:15PM (#16164240)
You just think you don't miss types but I guarantee you are doing a lot more manual work without types than with them, starting with refactorings which you must now supervise since it's pretty much impossible to guarantee the correctness of an automatic refactoring in the absence of type annotations.
Re:Convert React JavaScript Code to TypeScript with Proper T... by pixie_ on Tuesday January 16, 2018 @03:06PM (#16161853)
Being able to 'find all references' of a variable, do a safe global rename, and 'go to definition' saves an immense amount of time.

Not to mention preventing tons of run-time bugs which saves a ton of times having to figure out.

Re:Convert React JavaScript Code to TypeScript with Proper T... by Waterluvian on Tuesday January 16, 2018 @02:07PM (#16161158)
I'm actually really happy to hear someone call it a "no-brainer". That's an indication that it's likely a good fit at any scale. I was always concerned that it was too much at smaller scales.

I will create the world's ~first~ millionth to-do app to experiment.

Re:Convert React JavaScript Code to TypeScript with Proper T... by brianshaler on Tuesday January 16, 2018 @02:19PM (#16161307)
Even though I'm someone who doesn't reach for TS by choice (have had to use it for a couple of projects) I would add that even in a small or simple app, if you ever work with abstractions or wrapped values, you'll quickly feel the benefits of having types.