5 ms·
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 th
by renke1 10y ago
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?
- spion 10y agoImmutable.js (https://facebook.github.io/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 kinda useless. A nice typescript-friendly alternative to redux+immutablejs is MobX (https://mobxjs.github.io/mobx/getting-started.html https://mobxjs.github.io/mobx/getting-started.html). It does go a bit against the latest cool and hip trends (immutability, functional programming), but IMO its quite brilliant
- tomduncalf 10y ago+1 for MobX being quite brilliant. So much fun to write an app with. Not saying it is the best solution for every case but if you work with React, you really owe it to yourself to try it.
- renke1 10y agoI see, but using types for some parts of your code is still better than using none. And yes, actually I am using MobX, too, it's really a good choice for React. Although I miss redux-saga sometimes.
- spion 10y agoIts not just TypeScript's fault though. Its not impossible to design an immutable library which has an API that can be properly typed with TypeScript, e.g. https://goo.gl/7tAIuq https://goo.gl/7tAIuq
- smt88 10y agoFunctional 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.
- Roboprog 10y agoWe finally have tolerable garbage collectors.
- smt88 10y agoAnd languages like Rust, which are working toward eliminating the need for a garbage collector.
- Roboprog 10y agoI think I would rather do future "systems level" work in Rust than C, but I'm not sure it would eliminate the desire for automatic memory management in a casual or "ENTERPRISE!!!" (... no intelligent life here, Scottie) app :-)
- smt88 10y agoI haven't used Rust enough to comment myself, but other people have said that Rust essentially does have "automatic" memory management (in the sense that you must manage the memory in order to get your program to compile). People say it works most of the time, at least. Rust is trying to make that as painless as possible, so it'll be interesting to see how painless it really is.
- spion 10y agoWithin JavaScript, (pure) functional programming is a new trend.
- hokkos 10y agoWhy use Immutable.js Record if you can make your own typescript immutable classes ?
- Bahamut 10y agoI feel like TypeScript needs some work in areas around typing methods - for example, I ran into type issues when trying to go more functional via ramda.js (http://ramdajs.com/ http://ramdajs.com/) using stuff like compose, and ultimately it felt like a limitation of TypeScript.
- Roboprog 10y agoRamda is pretty cool. It's also a really good introduction to use-cases for partial function application ("currying"), vs silly "adder" examples. (think of partial function application as dependency injection for FP)
- spion 10y agoTo properly type Ramda, you need higher kinded types, which are not yet a feature of TypeScript. Though I find that Ramda's curried style isn't that useful now that we have arrow functions...
- Roboprog 10y agoHmm. I find that classes and subclasses aren't all that useful, now that I can use higher order functions :-) (I still use classes/objects for services with multiple related operations or polymorphism, but not for one trick pony "Executioners" for which Java would use a lambda -- which is what ES6 arrow funcs look like) I wish I could vote the grandparent post up more.
- spion 10y agoWhat I meant is that pointfree style (which is what Ramda implements) isn't that great in JS: * JavaScript is not suited for it (no composition operator, no interop with existing multi-argument functions) * It doesn't improve readability over arrow syntax. compose(f, flip(g)(y), h) vs x => f(g(h(x), y))