News for hackers. Stuff that matters.
Re:TypeScript at Google by MBCook on Sunday September 02, 2018 @12:11AM (#17895491)
Have you spent any real time with Flow?

As I’m starting to get into the modern front end world… I do want the safety of a stronger type system but it doesn’t look like the React ecosystem has really decided which way to go.

TypeScript is popular. But flow was developed by Facebook and so it’s obviously heavily used by some of the top people.

I’ve only been reading about them, I haven’t chosen to use one yet. But I’ve been leaning on flow since it’s developed by the React team at Facebook.

Re:TypeScript at Google by ggregoire on Sunday September 02, 2018 @03:09PM (#17898138)
I've reported 5 bugs about Flow and can list at least 10 other bugs reported by other people that I experience on a daily basis. Most of them have been upvoted by hundreds of people. Most of them have been opened 1 or 2 years ago. Most of them don't have a single reply from people working on Flow (or one of these: "yes I guess it's a valid point", "pull requests are welcome", "it's not a bug" , "we would have to rewrite a lot of stuff", without any follow-up).

That's what really frustrates me about Flow after using it for many years. We shouldn't have to rewrite valid code, write unreadable workarounds or add // $FlowFixMe annotations to avoid Flow's issues. I lead a small team of junior developers to whom I presented Flow. We now use it everywhere. But they often experience difficulties when they try to type their code. When I see what blocks them, my answer is too often "oh yeah, it's a bug in Flow. There is an issue about it on GitHub opened in 2016".

I'm right now waiting for this https://github.com/facebook/create-react-app/pull/4837 to be merged to move all my projects to TS.

Edit: and I don't blame the devs working on Flow. I guess it's more a priority issue at Facebook. Or maybe they just gave up on the community support since TS is too ahead.

Re:TypeScript at Google by eropple on Sunday September 02, 2018 @12:53AM (#17895624)
I've spent time with Flow, and I like some aspects of it (the type system seems a little more expressive, at least in the ways I know how to bend it). But it seems like TypeScript has fairly soundly won, as far as the two of them go. I've moved to writing almost exclusively TypeScript and I really don't regret it.
Re:TypeScript at Google by Vinnl on Sunday September 02, 2018 @04:25AM (#17896168)
Although it's clear that Facebook's libraries, among which React, favour Flow, there's strong community demand for TypeScript even around React. Thus, the type definitions that are available for React are excellent, Redux even includes its type definitions natively, and most of the large tools in the React ecosystem work pretty well with TypeScript.

The main large project you're likely to use that does not really play well with TypeScript yet is create-react-app. There's a TypeScript fork [1] which works reasonably well, but "reasonable" is not really what you'd hope.

That said, the strong community push means that they're at least considering it. [2]

[1] https://github.com/wmonk/create-react-app-typescript [2] https://github.com/facebook/create-react-app/pull/2815

Re:TypeScript at Google by acemarke on Sunday September 02, 2018 @11:06AM (#17897224)
We're actually looking at removing the type definitions from the Redux core and punting them over to DefinitelyTyped, because neither of us primary maintainers use TS ourselves and we don't have the experience to maintain the type definitions.

Also, the CRA-TS fork runs, but the one time I played with it was when I tried to help another team set up their project, and that's when I found out it has _ridiculously_ restrictive default linting rules. Every lint error is a compile error, and it flags things like using arrow functions in render methods, which is absurd (see discussion at https://github.com/wmonk/create-react-app-typescript/issues/... ).

Re:TypeScript at Google by joshtynjala on Sunday September 02, 2018 @06:14PM (#17898975)
The first thing I do in a new CRA-TS project is make the tslint.json rules default to warnings instead. Or just disable them completely. After that, it's great! I'm actually surprised that they still haven't loosened the rules after Dan called it out a month or two ago. Seems like an easy enough fix to at least make them warnings until they choose better defaults.
Re:TypeScript at Google by Vinnl on Sunday September 02, 2018 @04:31PM (#17898496)
Haha right, it's still the case that the type definitions for Redux are very much usable though :)
Re:TypeScript at Google by styfle on Sunday September 02, 2018 @07:49AM (#17896654)
I agree, the TypeScript team loves React and one of the reasons I started using React was because JSX/TSX is one of the few ways to type check views.

I have been maintaining some boilerplate to demonstrate TypeScript + React SSR that should point the reader in the right direction https://github.com/styfle/react-server-example-tsx

Re:TypeScript at Google by ggregoire on Sunday September 02, 2018 @03:36PM (#17898242)
Here is another PR, more recent, based on Babel 7 and its TS support: https://github.com/facebook/create-react-app/pull/4837

I'm waiting it to be merged to switch to TS.

Re:TypeScript at Google by Raphael on Sunday September 02, 2018 @05:23AM (#17896321)
Create React App is the first link that TS gives you in "getting started". Is there something wrong with it?

https://github.com/Microsoft/TypeScript-React-Starter#typesc...

Re:TypeScript at Google by pmoleri on Sunday September 02, 2018 @10:33AM (#17897114)
CRA is a set of packages, among which the most important is react-scripts (contains all build and publish commands). For Typescript you use rect-scripts-ts, a fork that usually is some versions behind the main one.

It does work fine, but sometimes you don't get some of the gooddies that you get in the latest js version.

Re:TypeScript at Google by _frog on Sunday September 02, 2018 @12:16AM (#17895508)
From my personal experience, Flow prioritises soundness in its type system, and thus can catch some bugs that TS won’t, but the TS tooling and editor support is drastically better than Flow’s.

Edit: oh and it’s worth noting that I’ve had much more luck finding TS definitions for third party packages than I have with Flow.

Re:TypeScript at Google by MBCook on Sunday September 02, 2018 @12:59AM (#17895639)
Could you expand some more on the tooling/editor support?

I’ve only done a cursory look. My editor (IntelliJ) supports both to some level. Webpack/Babel do too.

I’m very new to writing React and modern front end JS so it’s quite possible there are things that I should be looking out for that I don’t even know about.

Re:TypeScript at Google by nojvek on Sunday September 02, 2018 @01:49AM (#17895786)
Typescript compiler architecture is quite different to flows. Typescript was written from the get go to provide really fast and accurate intellisense to IDEs. The newer refactoring powers are super nice too. Most ides just ask typescripts language service “hey, my user’s cursor is here, what should I show for code completion?”

I think that’s what differentiates TS from flow. Typescript thought about the whole developers workflow while flow is just a compile time typechecker.

Re:TypeScript at Google by alangpierce on Sunday September 02, 2018 @02:37AM (#17895914)
To Flow's credit, their language server does provide IDE features:

https://github.com/flowtype/flow-language-server#supported-f...

I still have found TypeScript to be an overall more pleasant developer experience, though.

Re:TypeScript at Google by nojvek on Sunday September 02, 2018 @11:30AM (#17897308)
That’s awesome, I didn’t know that.
Re:TypeScript at Google by Bahamut on Sunday September 02, 2018 @02:27AM (#17895889)
At this point, I think Flow clearly has a minority mindshare & is looked at more skeptically all around the JS ecosystem, and maybe even the React ecosystem based on what I see talked around. TS does a much better job integrating with existing JS and is much more practical about incremental updates whereas Flow bleeds all too easily into needing to add typing to a significant amount of code in order to add a type.

That's not to say that either TypeScript or Flow are perfect - they both are constraining with typing when it comes to composing functions last I checked.

Re:TypeScript at Google by dvlsg on Sunday September 02, 2018 @03:44AM (#17896077)
I didn't have too many problems with typescript and ramda. I occasionally have to explicitly send in types to the first function of a pipe, which is a little annoying, but for the most part it seems to just work for how I use it. What problems have you run into?
Re:TypeScript at Google by leppr on Sunday September 02, 2018 @12:03PM (#17897435)
Have a look at the typescript declaration for Node's util.promisify (sorry on mobile can't find it right now). It's something like 10 lines long and covers only a handful of cases.

It's not something you'd want to find in the middle of your code, yet you may have to if you want to do generic/functional programming in TS.

Re:TypeScript at Google by machiaweliczny on Sunday September 02, 2018 @01:22AM (#17895701)
I worked with both. Without going into details - I recommend TS as it's better documented and easier to work with. With 3.0 they also improved error messages.

EDIT: one thing I miss from flow is https://github.com/gcanti/babel-plugin-tcomb - it's quite handy to spot data errors (before you have big static coverage)

Re:TypeScript at Google by Devagamster on Sunday September 02, 2018 @12:48AM (#17895605)
For what it's worth typescript is developed by Microsoft. Doesn't get much bigger than that
Re:TypeScript at Google by MBCook on Sunday September 02, 2018 @12:57AM (#17895634)
I know, and that’s a definite plus. I don’t have to worry that it will go away or lose all the main contributors.

But is not developed by the same developers/company as React.

I will say given what TS is competing against the fact that it so well used is rather compelling. I know all of Angular is also written in TS. It’s clearly very heavily used.

Re:TypeScript at Google by murukesh_s on Sunday September 02, 2018 @01:09AM (#17895668)
React can fade but JavaScript won't..(it could only evolve). outside react Typescript is the clear winner and even most of the react projects I am seeing is using Typescript. I would say Typescript is the clear winner. Also VSCode is now far popular than other editors which is developed by Microsoft as well..
Re:TypeScript at Google by nojvek on Sunday September 02, 2018 @01:51AM (#17895793)
Also typescript and React go really really well because typescript can do tsx which is a strongly typed flavor of jsx.

Being able to use good code completion when using other people’s components is a huge boon.

Re:TypeScript at Google by pas on Sunday September 02, 2018 @09:14AM (#17896882)
Isn't React in itself a view library? What's there to develop on it?

I'm really interested in this, as I'm a happy Angular user. (I'm primarily a non-frontend dev/tech/ops, but I occasionally I do frontend development.) So every time I look at a React component/codebase I'm completely lost, and I'd like to understand why and what and how.)