Live data from Hacker News

If TypeScript is so great, how come all notable ReactJS projects use Babel?

discuss.reactjs.org

121–130 of 247 posts

Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?

#121
post #17

Earlier quoted context omitted.

My opinion is that all the extensions on JavaScript should be implemented as Babel plugins, including Typescript. That would solve all the compatibility problems. Well, when Babel first came out I also thought that it should have been a Sweet.js plugin so maybe I don't have the best understanding of this "transpiling" circus.

It's tempting to think this way, but it's a performance/complexity nightmare. If everything is a plugin, then you need ways for different parsers to talk to each other to deal with nested syntax, plus ways for different syntactic transformers to correctly handle nesting of certain things. For example, if you desired to implement a plugin for "thin arrows", and a plugin for JSX, how would you parse this? const x = } /…

(This is not disagreement with RyanCavanaugh; it's a question for expansion by the community.)

It seems like Perl 6 is trying to implement pluggable grammars that work like that. Can anyone here familiar with the Perl 6 ecosystem comment on how it's going over there? Can you feasibly write a module with 5 or 6 different grammar extensions? What's it like? My understanding of the situation has matched what RyanCavanaugh expressed here for a while, and I'm curious if people's experiences match it or not.

Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?

#122
post #20
post #16

Earlier quoted context omitted.

I recently started using TypeScript for my React projects and I am actually pretty happy. I am not actually sure what you mean by typed immutable records in this context, can you explain in more detail?

Immutable.js ( https://facebook.github.io/immutable-js/ ) doesn't have the greatest typescript type annotations. Due to limitations of TypeScript, there is no way to write types for immutable.js heterogenous maps (homogenous Maps and Vectors are fine though). Since immutable.js collections are recommended to be used with redux, and no one wants to bother using IMJS records instead of just maps, the types end up being…

Functional programming is quite old and I wouldn't call it a trend. I'd say it's more like an industry getting better at its craft, similar to the transition toward strong typing.

Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?

#123
post #113

Earlier quoted context omitted.

Well, the V6 release made babel modular, so the babel package is no longer the right one to compare against. Look at babel-runtime: 4,600,000 or babel-core: 4,300,000 vs typescript: 2,100,000.

Good call, that's a very different chart. https://npm-stat.com/charts.html?package=babel-core&package=...

It's irrationally irritating that September's incomplete stats are graphed incorrectly. Guess I need more coffee before dealing with JS in the morning.

Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?

#124

Earlier 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.

What's awesome about `pub`? If you're talking to someone like me who uses `npm`, `webpack`, and is now considering `rollup` ... what am I missing if I don't look at `pub`?

Pub is an all-in-one tool that can replace all those disparate tools.

You can't just pull your package from pub (leftpad).

Extremely trivial, but I prefer yaml to json, :)

https://www.dartlang.org/tools/pub

Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?

#125
post #43

Please don't bury this comment completely. I am going to be honest and tell you that I believe TypeScript is pure embrace, extend, extinguish from Microsoft. And I am amazed honestly that so many web developers are eating it up.

Under what mechanism would the "extinguish" part be at all possible?

It's generally done by having the new "extended" version be so superior that others can't stand using the original anymore.

Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?

#126
post #115
post #72

Earlier 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 :)

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?

#127
post #3

OT: is it me or is Babel incredibly slow in translating ES6 to regular JS?

It is. Try enabling the `compact` option or using something like Buble [1]. [1]: https://buble.surge.sh

I use buble. It transpiles ES6 to ES5 2.5 times faster than babel on average. But be aware that buble is still a work in progress and only supports a subset of ES6 features. A very usable subset, but a subset nonetheless.

Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?

#128

Earlier quoted context omitted.

> I think you meant replacement of JS here. I guess it depends entirely on what you think of JS as a language. I, for one, would rather a language that fixes core issues with JS, instead of just being a superset of JS. If I were aiming to replace JS, I'd fix what Dart does, but I wouldn't stop with merely fixing what Dart does. Dart, despite being an entirely new language, has a less expressive type system than TS. I…

> has a less expressive type system than TS Care to elaborate on that? As for the rest of your comment, I'm with ya. I guess they're reasoning behind that was they thought a lot of development would start out untyped with additional types added as development progressed. I think that assumption didn't pan out, at least that's not how I do it. Official answer from https://www.dartlang.org/faq : "Q. But don’t you need…

>Care to elaborate on that?

I'm not the OP, but TypeScript supports union types (A | B ; a type that can be either type A or type B) and intersection types (A & B ; a type that is both A and B), while Dart doesn't. https://www.typescriptlang.org/docs/handbook/advanced-types....

Typescript also has structural types, like Go and OCaml, which many people find nicer than nominal types. Structural types mean if I have an interface Blaz with two methods Foo and Bar, if I have an object MyObject with Foo and Bar methods of the same types then my object counts as a Blaz, while nominal types mean I have to write something like MyObject extends Blaz.

Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?

#130

Speaking as the person who implemented JSX support for TypeScript, I question the premise! JSX support (and implementation of React semantics for typechecking that JSX) was a very popular feature request. I can tell you just from how quickly people notice when something JSX-related changes in the nightly build that there are a lot of people using TypeScript with React. Also, since this seem to be a popular misconcept…

> JSX support in TypeScript is not wedded to React.

Agreed. Here's an example of JSX in TypeScript that has nothing to do with React. UI Builder is a templating library, just like Mustache, but much better because you get full intellisense and compile-time checking for the template:

https://github.com/wisercoder/uibuilder

Post reply on HN