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.
If TypeScript is so great, how come all notable ReactJS projects use Babel?
181–190 of 247 posts
Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?
#182TypeScript 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.
Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?
#183I 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?
#184I'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?
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?
#185Earlier 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.)
Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?
#186Earlier 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…
Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?
#187Earlier 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…
Re: If TypeScript is so great, how come all notable ReactJS projects use Babel?
#188Earlier 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…
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?
#189I'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…
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?
#190Please 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?
Then when everyone's hooked on VS Code BAM VS Code Pro Extreme Edition!