TypeScript works very well with React, less so with Redux/ImmutableJS. We just moved our app from Redux and ImmutableJS to mobx and it's been a treat: we now get full typing and it's much less verbose. We don't need to repeat the payload definition at every point, we have a store where we call a method and that's it. Highly recommend checking out mobx if you use TS.
mobx seem to be one year old, that not enough.
If TypeScript is so great, how come all notable ReactJS projects use Babel?
141–150 of 247 posts
Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?
#142I've been using React + Redux + Typescript stack and I've been quite happy with it (It's hard for me to image how you could do big refactoring without TS). The fact that components props are verified by compiler instantly when I type is a big win. I believe with PropTypes you can't specifically describe what is the shape of your data, for example object with property of such name and the value of this property is obj…
Don't you have React.PropTypes.shape({ foo: React.PropTypes.string, bar: React.PropTypes.shape({ fieldNum: React.PropTypes.number }) }) ? I'm not saying it isn't verbose, but I'm pretty sure that as of a few months ago, this existed in React natively.
Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?
#143I was always wondering why HN crowd is ok with TS and so prejudiced against Dart - Dart has NG2, await async in older browsers and good tooling (webstorm, vscode) and much saner package system. When doing lot of small web apps - it's easier to mantain.
At least in my view, there's a couple of big things: Dart doesn't introduce that many advantages over JS for all of its differences, and TS introduces many of them with a smaller diff; there's also the presentation of it—Dart was originally presented as a wholesale replacement of Dart, to ship in all browsers, the language more or less as a fait accompli, which rubs plenty of people the wrong way.
Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?
#144Earlier quoted context omitted.
Dart has gradual typing > working with existing build tools and module systems I'd say they replaced it with a better tool, pub. The one good argument you have there is .d.ts files. Dart lacks them, but there are tools to generate js bindings from those same .d.ts files. https://github.com/jirkadanek/definitely_typed I haven't used it though, so I can't say if it works as advertised.
> I'd say they replaced it with a better tool, pub. Right but that route ends in forcing people to leap to a whole different ecosystem before they can even try your thing. Whereas with typescript you could put a single .ts file in your existing project without messing with anything else.
Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?
#145Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?
#146Earlier quoted context omitted.
As far as I've seen, it's really only Object spread (likely ES2017 feature) that's commonly used that is not yet supported by TypeScript. Microsoft has promised support for it in TS 2.1, and generally stays on top of ECMAScript proposals that have gained enough traction that they seem likely to ship.
On the other hand, Flow is removed from the code transformation, so it doesn't have to bother with keeping up with the spec. That's a pretty strong point in Flow's favor in my opinion, single responsibility principle and all that :)
Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?
#147The main reason for using Babel was async/await. However, the lastest TypeScript verion (typescript@next) can compile async/await for older browsers, so there is no reason for me to use Babel anymore.
Things like babel-core are still a must though.
Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?
#148Earlier quoted context omitted.
On the other hand, Flow is removed from the code transformation, so it doesn't have to bother with keeping up with the spec. That's a pretty strong point in Flow's favor in my opinion, single responsibility principle and all that :)
You can do that in TypeScript too: just target ES6, use all the features like spread/rest and async/await, then compile the result with Babel.
Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?
#149Earlier quoted context omitted.
Sorry for my ignorance, but does that amount to loading a library on demand? If so, yes, Dart can do this: import 'package:deferred/hello.dart' deferred as hello; // When you need the library, invoke loadLibrary() using the library’s identifier. greet() async { await hello.loadLibrary(); hello.printGreeting(); }
That does indeed work. I just tried it, and it works beautifully. The only problem is that the main output js file is still 107kb, quite large.
Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?
#150I was always wondering why HN crowd is ok with TS and so prejudiced against Dart - Dart has NG2, await async in older browsers and good tooling (webstorm, vscode) and much saner package system. When doing lot of small web apps - it's easier to mantain.
Dart is a special cookie. You can't use dart with all of Javascript's ecosystem.