News for hackers. Stuff that matters.
Re:What I wish I knew about React by tenaciousDaniel on Wednesday April 29, 2020 @09:35AM (#23018904)
I've been considering the jump into TS, but I don't want to end up in a coffeescript situation (i.e. language is dead, but code lingers on and has to be converted back to JS at some point, rather painfully). Do you think it's worth it?
Re:What I wish I knew about React by slewis on Wednesday April 29, 2020 @10:21AM (#23019563)
Yes. It’s built by Microsoft and has huge adoption. Typescript is here to stay.
Re:What I wish I knew about React by akie on Wednesday April 29, 2020 @12:11PM (#23020862)
What if most of TypeScript is embedded into the next version of JavaScript, as happened with Coffeescript?
Re:What I wish I knew about React by zdragnar on Wednesday April 29, 2020 @12:41PM (#23021174)
Typescript offers almost no runtime behavior. With a few exceptions, everything is stripped out, and it only offers to transpile modern JS features to older browsers. CoffeeScript was all about an alternate syntax for runtime behavior.

JS isn't going to get compile time anything. There was an attempt at adding "strong mode" by one of the google / chrome teams iirc and that went nowhere.

Re:What I wish I knew about React by Zarel on Wednesday April 29, 2020 @01:33PM (#23021852)
All I really wanted was to allow type annotations in JavaScript. So you wouldn't need a compile step while running (JavaScript would just ignore the type signatures), but TypeScript could check it whenever. I believe this is the approach Python uses.

I think there were discussions of doing that at some point, but it seems to have gone nowhere.

Re:What I wish I knew about React by StrangeSound on Wednesday April 29, 2020 @12:28PM (#23021036)
Then there's not really a problem. You learned how it works, and now it's one less thing to worry about
Re:What I wish I knew about React by hombre_fatal on Wednesday April 29, 2020 @12:42PM (#23021199)
Also, if Javascript got its own type system somehow (not gonna happen anytime soon), you could expect Typescript to compile to it.

And you could transition off of Typescript just as gradually as you could transition on to it.

Re:What I wish I knew about React by JackMorgan on Wednesday April 29, 2020 @10:35AM (#23019732)
I just switched a pretty huge project into TS, and I'm seeing for this team and project, probably 4 units of saved time in the PRO column, and 3 units of lost time in the CON column. Still worth it, but you'll need to learn and maintain a new thing, and sometimes doing a totally normal JavaScript thing would force you to write some pretty eldrich type signatures.
Re:What I wish I knew about React by fpoling on Wednesday April 29, 2020 @12:04PM (#23020785)
You may also consider Flow. It is literally JavaScript plus type annotations. The annotations can be even put into comments turning the files into vanilla JS making this very clear. So there is no danger that if FB abandons it one ends up with code that needs to be converted.

On the other hand Flow is much less cool than TypeScript these days. Plus using it for development under Windows have issues, although FB has started paying attention to them.

Re:What I wish I knew about React by Zarel on Wednesday April 29, 2020 @01:30PM (#23021822)
TypeScript annotations can also be put into comments. I like TypeScript's approach (JSDoc) better, actually, because it's how you'd want to annotate them even if you didn't have a typechecker, anyway.

Although I still hit enough annoyances that I'd go straight to `.ts` files for my next project.

Re:What I wish I knew about React by FeloniousHam on Thursday April 30, 2020 @11:15AM (#23031731)
We started out with Flow, but moved to Typescript not because it's "cool" (I suspect it's the Flow users who are smoking clove cigarettes in black berets), but because the language improvements and tooling support are a huge productivity boost. The killer is how flexible it is, it incrementally scales from straight JS to full-on type religion. You only have to use as much as you find useful.
Re:What I wish I knew about React by TechBro8615 on Wednesday April 29, 2020 @03:35PM (#23023215)
If you decide to make the jump, I found tsdx to be really useful boilerplate generator for getting started: https://github.com/jaredpalmer/tsdx
Re:What I wish I knew about React by mercer on Thursday April 30, 2020 @09:15AM (#23030436)
I've been doing less and less JS stuff, but I actually miss TS at times. I think it won't end up like CoffeeScript, and it's absolutely worth using if you need to write javascript!
Re:What I wish I knew about React by carry_bit on Wednesday April 29, 2020 @10:54AM (#23020002)
Unlike coffeescript which had a fundamentally different syntax, typescript is just modern javascript plus types.
Re:What I wish I knew about React by davnicwil on Wednesday April 29, 2020 @11:49AM (#23020613)
I agree and won't repeat this point in a sibling comment, but just a slight nuance is that there are in fact some extra features/syntax TS has that JS doesn't, such as enums.

You have to be aware these features would need to be manually converted back to JS were you ever to switch back. Honestly this would likely not be a significant amount of work, especially if you don't overuse them, but just to make you (GP) aware.