Live data from Hacker News

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

discuss.reactjs.org

181–190 of 247 posts

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

#181
post #91

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.

I've been using Typescript, React, and mobx and absolutely in love with how they all work together. For me the high-level summary is that the vast majority of my logic is moved out of React views and into stores / controllers / whatever, with almost no boilerplate to make them play nicely together. The way its coming along reminds me of Ember quite a bit, but I get to use React and POJO's.

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

#182
post #91

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.

I've been using Typescript, React, and mobx and absolutely in love with how they all work together. For me the high-level summary is that the vast majority of my logic is moved out of React views and into stores / controllers / whatever, with almost no boilerplate to make them play nicely together. The way its coming along reminds me of Ember quite a bit, but I get to use React and POJO's.

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

#183
post #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.

I use TS every day and it's a godsend, as long as you compare it solely to "using JS everyday".

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

#184

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?

I've been using discriminated unions on TS 2 to do this, and works quite well.

Example:

  const INCREMENT: "increment" = "increment";
  const DECREMENT: "decrement" = "decrement";

  interface Increment {
      type: typeof INCREMENT;
      payload: {
          inc: number;
      };
  }

   interface Decrement {
      type: typeof DECREMENT;
      payload: {
          dec: number;
      };
  }

  interface State { 
      count: number; 
  }

  type Actions = Increment | Decrement;

  function reducer(state: State, action: Actions) {
     switch (action.type) {
        case INCREMENT: {
             const { inc } = action.payload;
             return { count: state.count + inc };
         }
         case DECREMENT: {
             const { dec } = action.payload;
             return { count: state.count + dec };
         }
         default:
             return state;
     }
  }
Once TS figures out the action type is INCREMENT, it can infer the type of the payload. You don't need the Actions type either, you can just receive action: Increment | Decrement.

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

#185
post #171

Earlier quoted context omitted.

I guess they fixed it. Try it yourself. http://www.typescriptlang.org/play/ Argument of type 'string' is not assignable to parameter of type 'number' on line 3.

Sorry for the confusing comment -- I updated it. I was saying that it is strange for the linked post to talk about soundness being important when it's trivial to find an unsound Flow program. (This particular program is properly rejected by TypeScript but TypeScript is also unsound so there are plenty of other invalid programs that it accepts.)

I think it's a lot harder to get past TypeScript's type checker. It's probably possible, but I can't think of a way to do it off the top of my head without casting to any. It's a lot easier to show correctly executing javascript programs that would be rejected by the type checker.

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

#186
post #115

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

Flow understands some TC39 proposals, if you use the right flags: esproposal.class_instance_fields=enable but it chokes on ones it doesn't understand. I tried using Flow and RxJS in the same codebase. RxJS makes heavy use of the pipeline operator: stream::map(thing) vs map.call(stream, thing) Flow will stop checking types as soon as it sees ::. Babel parses it, but Flow runs in parallel, so it needs to be able to wal…

The pipeline operating is super speculative. I would suggest not using it yet.

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

#187
post #61

Earlier quoted context omitted.

I want to give Dart a chance, because most of it's features seem quite appealing. I decided to start learning JS/Jquery and then move onto to Dart. The fact that everything comes bundled into Dart as a whole dev environment (IDE, compiling,packaging,) and the interoperability with JS make it quite attractive. What is your experience doing web dev with and without Dart (JS vs Dart, pros and cons)? I'd be really intere…

I started off with C/C++, Java, then AS3 writing Flash games. Then js/jquery and I instantly hated it (js). There were just too many quirks, bizarre, unexpected behavior. Sure, I could learn it inside out and avoid these pitfalls, but why would I when there were better alternatives? I did use CoffeeScript after that, a beautiful little language, but only suitable for smallish projects. I need static typing for large…

Excellent, appreciate this thoughtful answer. So you mostly code games?

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

#188
post #86
post #67

Earlier quoted context omitted.

I don't think the point of WebAssembly is to target the DOM. I think it it's to provide a common low level API across browsers that many languages can target.

Sorry was referring to the infinite layers of transpiling and sub-languages that people talk about like it's normal, which I admittedly get why they exist, but it's still fucked. But that too. (though maybe wasm + canvas will let someone eventually implement a decent ui toolkit? Think I saw at least one attempt at this.) Current project could maybe benefit from TypeScript, and certainly async/await, but still wonder…

..and no i dont want to use VS Code either!

grumble grumble grumble

(Of course if yc ever decides to fund our small startup it should know that we are a team of forward thinking progressive individuals who will use the best and most robust tools available to us, who's views i do not necessarily represent)

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

#189

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 use Typescript 2.0 RC

No need to use the RC any more. 2.0 is out!

https://github.com/Microsoft/TypeScript/wiki/What's-new-in-T...

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

#190
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?

When using TypeScript subtly forces you into a MS toolchain.

Then when everyone's hooked on VS Code BAM VS Code Pro Extreme Edition!

Post reply on HN