Live data from Hacker News

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

discuss.reactjs.org

161–170 of 247 posts

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

#161

I would have switched to typescript but I had to rename EVERYTHING from something to something else in order to use TypeScript. If that's how "compatible" starts, well, no thanks cause clearly that's just the start of the pain. Compatible should be same files, new compiler = "just works".

I have not encountered this problem. Can you provide an example?

I'm guessing he/she is referring to using .ts instead of .js

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

#162

Earlier quoted context omitted.

> It would only increase the concept count in an educational setting where you want to only show the thing you're trying to explain. As someone who has written a long tutorial, this makes total sense. When I was first looking at the react ecosystem, it was very frustrating because of the high cost of picking pieces to work together. I really liked http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial... becaus…

This is basically my frustration with the whole trend toward smaller pieces over big monoliths. I don't need a best-in-class every tiny little thing; I just want reasonable tools I can expect to work together well.

The other nice thing is that bigger monoliths often (not always) make opinionated decisions. This is usually a good thing.

In my work I deal with a legacy system with an ExtJS GUI. The two ways that ExtJS fails to be opinionated are perpetual pain points for me and my team! One is: every component has a million optional configurations, not to mention all of the events you can listen on. For the most part this is great, but there was never any systematic separation for "here are the absolutely-required things, there are the things which are optional but must be configured together, and over yonder are the things which are totally optional." Then you could require that the required-configs were, say, statically known when you were deriving a concrete class from an abstract one. Instead ExtJS wanted to accept doing all of this stuff at runtime, so because it failed to take a strong stand on its required configs, when you inevitably forget to configure some of them, you get an error puked out from somewhere very deep in the framework, where the call-stack and error messages show nothing related to your class at all, just "TypeError: SomethingYouNeverCaredAbout is null." It would have all been saved if `Ext.define` looked for some "abstractProperties" array, and made sure that every new `Ext.define` either set abstract properties or propagated them, finally checking that whichever ones are still present in the `Ext.create` call are filled in. Simple descriptive error messages are then available when you forget a required config.

The other way ExtJS violates the principle is... God help you if you ever have to figure out how the underlying form submits and grid reloads actually work. You'd think with something so critical, it would be clear... it's not.

"My grid refreshes automatically when the underlying store loads. Great! The underlying store can be loaded or reloaded with the .load() method, which accepts a callback. Wonderful!" It starts off very promising. But then you dig deeper and find that the .load() method packages the params and the callback into some object and then calls some .read() method which doesn't exist on the class you're looking at (inheritance! go up to the superclass!). Once you've traced that down the actual .read() bounces to some .doAction() which repackages these into some `Operation{type: 'readAction'}` or whatever... and then this gets handed up to some Proxy object which then stores it in some meaningless array, because of course these things get batched together... if you're not sick yet you find out that the Proxy needs to push the stuff to some Reader and Writer, just in case you wanted to communicate with the server via XML instead of JSON, or wanted to store the resulting array under a key not named 'results'. But you don't want to do any of this because the query finally gets XMLHttpRequested somehow (God knows how) to some `router.php` which we stole from IBM[1] a long time ago, which finally took a stand, "I will accept these two inputs, send them to the backend this way, and emit one of two corresponding outputs." (Except for that then you open that and it contains code for some sort of `doAroundCalls` because apparently the original author[2] decided to vacillate on what they'd accept, trying to also allow you to bookend one RPC service with two other RPC services, which never happens because Ext.JS never does it!) It gets a little more complicated because there is one rather significant bug which nobody has ever fixed in IBM's router.php, which is that formHandler services get the $_POST params (an associative array) as their first argument whereas XMLHttpRequests get the `json_decode($HTTP_RAW_POST_DATA)` (a StdClass object) as their first argument, so there's no interoperability on the frontend or the backend. Happy debugging, you. It's all one big mess.

You begin to wish ExtJS had done what they eventually ended up doing[3], and just told people, "here is how you're going to do this thing. We have a Java router, a PHP router, here is how you set up your backend on these platforms..." That would have been very bold since ExtJS was originally just a set of helper classes to help automate GUI stuff with YUI, so I understand that the history made them feel a bit shaky about doing that, but... I really don't value that there's 10 layers of abstraction just in case I want to transmit the same stuff over-the-wire in XML rather than JSON.

If any developers of toolkits are reading this: please, please consider very firm protocols: "here is what you're going to send me, and here's what I'm going to respond with." Because, half of programming anyways is translating outputs to inputs; we all know how to write the adapters which connect the two. Please make your life really simple by not supporting a million different ways to do the thing. I promise, you're also making my life simple because even though I will grumble about spending a half-day writing that adapter, I will then save untold dozens of half-days because the overall architecture is modularized, "oh there's a bug in the adapter, my bad, but it's only a 5 minute fix." My communication with you must pass through a gateway; please limit me to only a very small choice of inputs which you are going to tolerate, and break very loudly at the gateway when I forget some of those. It's far better than having a nigh-undebuggable error somewhere in the middle of your framework code that I never want to read.

[1] http://www.ibm.com/developerworks/library/wa-aj-streamline/

[2] This could be Dan Dallala of Microsoft? His Gist appears to be an older version of the file and is one of the top results when googling strings out of the source file...

[3] It's not complete as to how the backend should be set up, but at least there is now a documented interface for this Ext.Direct communication. https://docs.sencha.com/extjs/6.0.1/guides/backend_connector...

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

#163
post #153

I am using TypeScript in a middle sized app (around 200 react components) and its help is invaluable for collaborating and sharing APIs. Currently it is based on redux, but I have a feeling I have to write too much code, I am looking into MobX as an alternative. I think TypeScript is the best thing that happened to the JS community in a long time.

Don't hesitate to jump ship to Mobx. No regrets at all, it was like trading in a Lada for a Toyota. And being written in typescript, the TS support is impeccable.

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

#164

Earlier quoted context omitted.

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.

No, that's not how that works.

EEE refers to the times when Microsoft would take an open standard--say HTML, or JavaScript, back when IE3 was actually the best browser on the market--shove in their own, proprietary, backwards-incompatible extensions, and keep calling it the same thing as the open standard.

But MS makes it very clear that TypeScript is a different language. It helps a lot that they don't even have the same name, y'know. Also, it's a system for specifically staying backwards compatible with open-standard JavaScript. Using TypeScript does not replace JavaScript. It supplements it.

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

#165

Earlier quoted context omitted.

> It would only increase the concept count in an educational setting where you want to only show the thing you're trying to explain. As someone who has written a long tutorial, this makes total sense. When I was first looking at the react ecosystem, it was very frustrating because of the high cost of picking pieces to work together. I really liked http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial... becaus…

This is basically my frustration with the whole trend toward smaller pieces over big monoliths. I don't need a best-in-class every tiny little thing; I just want reasonable tools I can expect to work together well.

The JS build system ecosystem could definitely use some help along the whole "reasonable tools I can expect to work together well" front. I swear, 30% of my time is spent fighting the build systems and their plugins that hate each other.

EDIT: to add, I think the TS team has done such a bangup job on Typescript that I would love it if they could create a build system as well. Some things that would be nice to have:

* Build-time loading of static resources (.json into js objects, html into strings, etc.)

* File watching and processing for more than just .ts/.js files

* Optimization. Not just tree-shaking and minification, but you could actually get a little more advanced due to the static types and ES6 modules.

* Environment-dependent compilation (compile these files in this way, inserting these static values where ENV variables are used in the source, etc.)

* Target capabilities analysis (ie. for this set of browsers and versions, what is the Lowest Common Denominator for browser capabilities, and ergo, what babel transforms and browser shims should be included?)

* Integrated contracts testing with test elision (ie. run these tests in these (karma? selenium?) environments and if failing, throw a compilation error or warning, and if passing, strip the tests from the compiled source).

* Source packaging (gzipping, etc.), and deployment plugins (ie. deploy compiled assets to S3, package for NPM, etc.).

All of these are pain points in Typescript projects, and all of them touch TS projects in such a way that it makes it even more painful in existing build systems.

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

#166
post #153

I am using TypeScript in a middle sized app (around 200 react components) and its help is invaluable for collaborating and sharing APIs. Currently it is based on redux, but I have a feeling I have to write too much code, I am looking into MobX as an alternative. I think TypeScript is the best thing that happened to the JS community in a long time.

Don't hesitate to jump ship to Mobx. No regrets at all, it was like trading in a Lada for a Toyota. And being written in typescript, the TS support is impeccable.

I wonder if such comments: http://disq.us/p/1bpl2ua are actually based on reality or just a plain rant.

I worked with SproutCore, Angular and others that tried to be "smart", and while it was awesome at first, in the long run it was hard to maintain.

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

#167

I'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.

You can also do ImageUser.propTypes = { image: CustomImage.propTypes }

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

#168

I do TypeScript every day for work, and honestly I don't see the point of it. I'm also of the opinion that the iterator pattern nonsense has ruined generated code quality for ES6 transpilers, and that ES5 getters and setters have made it considerably harder for JS engines to do high level optimizations (dead store elimination, invariant hoisting, load merging, etc.). The sky is falling. Anyway, you're not going to di…

> I do TypeScript every day for work, and honestly I don't see the point of it.

really? I'm assuming you never refactor anything.

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

#169

I'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.

Thanks, I didn't know that (I've been using React.js just a month, and from beginning with TypeScript)

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

#170

I'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…

I've also been trying to derive a good TS pattern for redux Actions/Reducers. Do you have any code examples online that you could point me to?
Post reply on HN