13 ms·
From TypeScript to ReScript
- ctenb 5y agoYou might be interested in trying PureScript as well. It has good FFI support and as a consequence there exist wellmaintained bindings into react etc. It can also run on other backends beside javascript, which makes that you can use it for backend programming too.
- greyblake 5y agoThanks for your comment! I am aware of PureScript and even tried it a little bit 3-4 years ago, but was not aware that it has good interops too!
- throwaway81523 5y agoYeah I also noticed Purescript was missing from your comparisons list. It's the only one of these that I've looked at much, and it seemed like the best of them, though I wasn't aware of the issue with ES6 modules. I don't use JS at all for now, so I haven't been up to date about anything in it.
- fbn79 5y agoI was looking to try PureScript but the lack of support for ES6 modules still halt me from invest time in that language (see https://github.com/purescript/purescript/issues/3613 https://github.com/purescript/purescript/issues/3613)
- ctenb 5y agoThat's right, though that feature is very high on the priority list, so it's probably going to be supported fairly soon.
- ReleaseCandidat 5y agoYes, out of all alternatives I looked at, I did choose PureScript because of the (relatively) easy JS interop (which Elm lacks), not needing the JVM and having types (Clojurescript) and the better async handling without the need of `then`s and the function 'pyramids' and, last, but not least, the lack of (C-) JS-Style syntax.
- skywal_l 5y agoA couple of strange things: * the use of decorators in even the most basic example * no async/await. You fall back to Promise.{then,resolve}. The example given is not that clear to me. * You can't have two files with the same name in different folders?? And in general, for me, the ability to be a little less strict at times makes Typescript way more easier to deal with. It's a 80/20 thing. Most of the time I want type enforced but in some situation, I know it's OK and I just want to move on with my day.
- Asraelite 5y ago> no async/await Doesn't this mean we're basically back to callback hell? This was one of the primary criticisms of Node before async/await was introduced.
- skywal_l 5y agoCallback hell was before the introduction of Promises. Promises tried to abstract away the callback mechanism and it made things a little clearer, but you still had the pyramid effect of successive Promises. Await/Async kind of streamlined all this.
- dsnr 5y agoI still somewhat prefer the readability of promises vs. await. I like the expressiveness of a then/catch as functions as opposed to try/catch blocks, which I‘ve always disliked. But I agree that await is more suitable for more complex scenarios.
- nsonha 5y agoasync/await is just a syntax sugar, most languages didn't have it until very recently when it became a trend or something. In OCAML it's just like any other monad you use the bind operator instead. No need for special keywords.
- lolive 5y agoI will probably be banned from any Haskell forum after that, but isn't the do notation a async, and the <- a await ?
- jatins 5y agoIn my experience with these typed alternatives to JS, as long as you stay within that language things are good and smooth. But as soon as you need to interface with 3rd part lib, that's when things start to get messy. Providing type declarations for every third party lib you might want to use, especially in an ecosystem like Javascript's which relies heavily on them, gets tiring pretty fast. Typescript manages to get past that because it has reached a level of adoption now that most popular libraries will have a @types/<lib> package also but it took a long while to reach that stage. Curious if anyone has used ReScript at a larger scale (and does not have the resources of, say, Facebook) and what's their experience been like.
- idontwantthis 5y agoTypescript is great because without it, you still need to determine a library’s types. It’s just that the type checking is only done in your head. If you need to add types to a JS library that still doesn’t have them for some reason, you’re actually doing less work than if you didn’t add them. Add the types as needed and you’re good.
- greyblake 5y agoI agree, ReScript has no big adoption (hopefully yet), and that's the biggest disadvantage in comparison with TypeScript. But somebody has to do the first steps...
- cies 5y agoThere's some project to get TS type annotations to work for ReScript. It'd be great if ReScript could lift on the work done by the TS community to produce types for many common JS libs.
- jatins 5y agoI wonder how would that work. Typescript has pretty advanced types like Template Literal Types[0]. Wouldn't ReScript need to support all those types? Or maybe it just resorts to `any` equivalent if I can't map a TS type to ReScript type. [0] https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html https://www.typescriptlang.org/docs/handbook/2/template-lite...
- shp0ngle 5y ago> Unfortunately, today it's necessary to understand difference between OCaml, BuckleScript, Reason and ReScript to navigate in the ecosystem comfortably I got hit by this literally yesterday. It took me a while to understand this mess.
- cassepipe 5y agoYup, that's a rough start. I don't see how any project could take off with rebranding and splitting from an already small community, Reason users, (itself a split a relatively small community, Ocaml users). It seems like the road to success is the other way around. Make it a little better while super easy to adopt and iterate on that à la TypeScript or Reason, which can be considered alternate syntaxes for Javascript and Ocaml users respectively and are super easy to adopt whereas forking Reason into yet another programming language that has no ecosystem/community and wait for it to grow is almost always the promise of a bad pain/benefits ratio. A more thorough explanation of the whole kerfuffle : https://ersin-akinci.medium.com/confused-about-rescript-rescript-reason-reasonml-and-bucklescript-explained-ab4230555230 https://ersin-akinci.medium.com/confused-about-rescript-resc...
- chrischen 5y agoA lot of the original community members were also functional programming enthusiasts and their recent shift to ReScript has been intentionally alienating them in order to make the language more palatable for newbies to gain marketshare from Typescript. I understand the motivation, but some of the changes involve opinionated omissions of features in order to steer the open source code bases away from more traditional FP paradigms.
- dsnr 5y ago> TypeScript's type system is over-complex since it tries to be a superset of JS. This is exactly why it got so popular, and TypeScript support in the JS ecosystem is so good. It's easy to just strip the TS metadata and you're left with working JS. This is why projects like esbuild managed to ship TS support so quickly (without type-checking). Good luck doing that with a new language. I for one am "all in" on TypeScript, with all its shortcomings it's just the best of both worlds, and so easy to get on board.
- elevader 5y agoAnd it works in both directions. You can "easily" (I mean, this is JS afterall so this heavily depends on the degree of toolchain hell chosen) move to the TS toolchain and rename your files to have the .ts extension and you have a valid TS project and benefit from the inferred types for your code. Type annotations can then be added later on as you go. And the syntax everybody already knows stays valid. This is a huge benefit compared to something like ReScript because it makes adoption really easy. With the obvious downside of not having nice features like pattern matching.
- kvathupo 5y agoI agree that TS eases the transition from JS, but I'd qualify your statement by saying it's not the toolchain that's a source of headache. Ideally, one should compile TS with `--strict`, otherwise there's little difference with JS. With this in mind, it's quick and easy to switch to TS tooling. Afterwards, one can incrementally adopt stricter typing, culminating in adding `--strict` to your `tsconfig`. In reality, since `--strict` is false by default, I'm concerned people erroneously assume that their JS code is type-safe after the first step, when it really isn't. In other words, it's no different than JS, except in name only!
- _old_dude_ 5y agoThe problem with the add types later approach is that in the end you have half baked .ts files left and right. And it becomes increasingly difficult to know when something compiles if it's because it's correct or because there is an any somewhere.
- elcapitan 5y agoIs ReScript the same as ReasonML, and is it gaining real traction this time? A couple of years ago I looked into Reason and really liked it, but the toolchain wasn't going anywhere and it didn't see a lot of adaption back then.
- ronenlh 5y agoYes and no. The syntax has been updated to make it less OCaml and more JavaScript-like. ReasonML can compile to native, rescript can’t. Reason still exists as a separate project, and projects that have been rewritten into reason will not necessarily switch.
- pbiggar 5y agoIn theory this is correct, but in practice Reason(ML) is dead. Or it was the last time I checked a month or two ago. ReScript lives on though.
- cies 5y agoSuch a pity they've become two projects. To have on lang for both BE and FE is really nice.
- elcapitan 5y agoWell technically I guess you could still have that via node, just not native as with the Ocaml compiler?
- 5y ago
- onox 5y agoI've been using ReScript for a few months now. So far I mostly like it, but it takes some time to get used to it. The error messages can be confusing though so I try not to depend too much on type inference. The other downside is that some bindings for some of the web apis seem to be missing (like for the types in the Dom module). Btw, for Material UI there are already bindings [1] [1] https://github.com/cca-io/rescript-material-ui https://github.com/cca-io/rescript-material-ui
- PUSH_AX 5y ago> The error messages can be confusing though I mean TS has that problem too anyway. They're terrible.
- ronenlh 5y agoAmazing in depth overview. There are useful comments in my (shameless plug) post about my same transition: https://news.ycombinator.com/item?id=25845147 https://news.ycombinator.com/item?id=25845147
- asplake 5y agoInteresting reference to Seed https://seed-rs.org/ https://seed-rs.org/ – first I've heard of it. Anyone using it?
- greyblake 5y agoWhatlang demo webpage is implemented with seed: https://whatlang.org/ https://whatlang.org/
- moritonal 5y ago"This means having two files with the same name in different directories is not allowed." "ReScript has no async/await support." "ReScript has no special debugging support or source maps." Sorry but aren't these issues fairly glaring problems? They're hand-waived away because the project is small, but I feel like they'd become quite major eventually?
- Deukhoofd 5y agoThe first one is a design decision that I consider a bit "meh" as well, but I can see why they did it. The third one I'm assuming is just a thing that hasn't been gotten around to, and I think is reasonable to not immediately expect from a smallish project. The second one does sound like a fairly major thing though. The promise syntax shown in the article to get around the issue looks like a massive code smell.
- nicoburns 5y agoEven just the first one would seem to make large projects a complete non-starter.
- awb 5y agoI guess instead of: /index.res /posts/index.res You’d need: /index.res /posts/posts_index.res Pretty annoying
- frenchyatwork 5y agoJust write in the style where all your names are like 'folder1/folder2/folder3/folder1Folder2Folder3Thing.ts`. (to be clear, this is sarcasm, please don't do this!)
- oauea 5y agoJust don't use folders.
- elevader 5y ago> Despite requiring very verbose type annotations, TypeScript does not have a sound type system, meaning it does not guarantee the absence of type-related errors in runtime even if everything compiles fine. Does ReScript solve that? If so, how? In my experience this is mostly an issue with data/functions coming from outside sources (Return values from HTTP calls to endpoints you don't control being a big culprit). Sure, you can write type definitions for that but that doesn't mean anything unless everything is manually validated/checked at runtime as nothing really guarantees that the type definitions are actually correct. Does ReScript handle that automatically?
- chrischen 5y agoAt this current time rescript is still basically ocaml, and accepts ocaml syntax. So it has the Ocaml typechecker.
- greyblake 5y agoThere still "weak" points, where incorrect typing can be introduced, e.g. incorrectly written bindings. Regarding data from HTTP call in theory they can be cast to any type abusing `external` keyword which is meant for binings. But common and recommend approach is to write codes. Codec would perform all the necessary checks to ensure that the data are in correct shape to satisfy the type restrictions. You can see some examples here: https://github.com/greyblake/from-typescript-to-rescript/blob/master/rescript/src/shared/Types.res#L66-L73 https://github.com/greyblake/from-typescript-to-rescript/blo...
- the_gipsy 5y agoFor what it's worth, Elm does the runtime checks by means of forcing you to write "de/encoders" that must match the types.
- smt88 5y agoSo does TypeScript if you have strict settings. Your input data will be untyped and you will be forced to determine its type before you use it.
- ostenning 5y agoReminds me of CoffeeScript, and look where that went.
- blorenz 5y agoAgreed. Though we did get the glory of fat arrows from that misadventure!
- greyblake 5y agoCoffeeScript is a language without static typing. Despite this, CoffeeScript actually made a real revolution when it was introduced.
- phaedryx 5y agoThey stole the good ideas from it and put it into ES6?
- dmitriid 5y ago> there was a type mismatch, but the error the compiler reported was quite far from the original error made by me. It's not a compiler's fault, the fault was purely mine. No. No it's not. It's the compiler's fault.
- dllthomas 5y agoWhy not both?
- dmitriid 5y agoBecause it should be the computer's job to aid the user, not the other way around :D Though proper error reporting is quite hard and too many tools transfer the burden of figuring what happened to the user.
- dllthomas 5y ago> it should be the computer's job to aid the user Most languages "aid the user" with better error locality by requiring the user aid them with far more type annotations. Lack of error locality is presently a downside of relying on pervasive type inference (at least in both OCaml and Haskell). I expect there's room (and responsibility) to improve, and so I do accord the language some of the blame. But error locality can be recovered by adding back some of the annotations that another language might require, and it can be optionally deferred until the locality is desired. I don't think it's right to say that that's requiring more help from the user than the baseline, and I think it's right to place some of the blame on the user misusing the tools if they're not adding enough annotations to get the kind of error locality they want from the tool they're using (as noted in the article, the author stopped doing that, although it may've been an overreaction).
- jillesvangurp 5y agoTypescript is a gateway drug for Javascript programmers. It's backwards compatible. So, it's easy to get started. However, it comes with a lot of compromises to enable that backwards compatibility. If you think of javascript as a compilation target rather than a language, typescript is just one of many languages that can target that. And I'd argue that even javascript these days is transpiled to what runs in the browser. It might be the same javascript dialect. But minified/obfuscated etc. But more commonly, it's more than just that. In short, modern javascript development involves transpilation/compilation. It just does. The whole scripted/interpreted vs. compiled distinction that people used to make is less relevant these days. It pretty much always involves some kind of compiler. And if you are going to use a compiler, you might as well use a proper one that does some useful stuff like prevent bugs, check types, optimize, etc. Typesystems have come a long way in the last 20 years. In short, there is no technical reason to be using Javascript exclusively in 2022. Whether it's Clojure, Elm, Kotlin, or other languages; they each have in common that they have js transpilers that work quite nicely and type systems that are definitely a level up from the unholy mess that is Javascript's "it could be a string or some object or undefined, but who the hell knows". Some people actually prefer that. Other people want no part of that kind of sloppy typing. And the good news is that there is no technical need to have any of that. I've been using Kotlin-js for the last year for a web application. The tool chain has some rough edges but the language is a joy to work with generally also for browser development. Definitely an upgrade over typescript, which I've also used in the past. And we have quite a bit of multi platform kotlin code that we also use server side. A lot of what we do is increasingly multiplatform and not explicitly dependent on the JVM. We could choose to use that code also on Android or IOS (via the native compiler). With compose web and other emerging Kotin web frameworks and the upcoming WASM compiler for Kotlin, I suspect it's going to become a lot more popular to use for web applications. With WASM, transpiling to Javascript will ultimately become a thing of the past. If you are compiling, you might as well produce WASM. Short term there are some open interoperability issues with browser APIs of course. However, nothing that can't be solved long term.
- greyblake 5y ago+1
- 5y ago
- azangru 5y agoNone of the available alternatives to typescript — Elm, Purescript, Reason/Rescript — give me the same feeling of confidence in the future direction of these projects as typescript does. At least typescript is very closely aligned with the development of javascript; and it's also very widely used. - Elm: not general-purpose enough (only useful for UIs), plus has a tendency of making drastic changes between versions (remember how loudly people complained here? [0]) - Purescript: the designer of the language, Phil Freeman, has stepped away from this project, and it doesn't seem to have gained sufficient traction - Rescript: I'm put off by its ocamlness; and worry whether it will repeat the trajectory of Flow, which has essentially become irrelevant [0] - https://news.ycombinator.com/item?id=22821447 https://news.ycombinator.com/item?id=22821447
- cardanome 5y ago> Elm: not general-purpose enough (only useful for UIs), plus has a tendency of making drastic changes between versions (remember how loudly people complained here? Not really, it just has a slow release schedule. Over time it is relatively stable. Not a single thing has changed about it the last two years and the creator has communicated that it will probably stay mostly the same for quite a while. Yes, there have been some bigger changes in the past but that is fair game for software that hasn't hit version 1 yet and it was communicated that it might happen. The drama is mostly an issue caused by misaligned expectations: Many people assume that open source projects should be developed openly with everyone being able to contribute and having a say about the direction. Evan, the author of Elm, prefers to keep tight control of everything. The approach has some advantages and disadvantages and I can see why people might decide to stay away from the community but honestly if you just want to get work done in Elm, it is not much of an issue either way. Elm is probably the most stable and reliable choice for frontend code and helps avoiding the churn that happens in the JS ecosystems.
- fbn79 5y agoIdris 2 looks promising... I suggest keep an eye on it https://github.com/idris-lang/Idris2 https://github.com/idris-lang/Idris2
- metta2uall 5y ago
- Tade0 5y agoAs a sort of litmus test I use the number of stars a superset of(or language compiling to) JavaScript has on GitHub and how that compares to fartscroll.js: https://github.com/theonion/fartscroll.js/ https://github.com/theonion/fartscroll.js/ By this measure ReScript is still a niche language.
- afavour 5y agoI’m curious as to whether this is a good measure. I use a ton of modules and I don’t think I’ve ever once starred a GitHub repo. I doubt I’m alone.
- Tade0 5y agoIt's more of an appeal to language designers to not get too cocky too soon. After all if a joke script has more followers then it's better to tone down the marketing material.
- ltr_ 5y agovery interesting language, I'm looking for a new programing language for our AWS lambdas, is ReScript a viable option for backends too?
- yawaramin 5y agoYes--if you target Node.js which I believe is supported first-class for AWS Lambda. ReScript compiles to very clean JS that looks almost hand-written. Should be easy to deploy to a lambda.
- mxz3000 5y agoThe quality of the generated JS is a bit irrelevant as they'll probably want to minify the generated JS to reduce the size of the assets and make cold starts quicker anyways.
- overgard 5y agoI feel like the amount of time you would spend dealing with weird interop is far far greater than the number of times typescripts unsoundness would get you (hardly ever in my experience)
- codeptualize 5y agoI've used Rescript (and ReasonML before that) for side projects, I really like it. I'd say it main strength is also its main weaknesses; it's not JS with a C# sauce (like TS), it's OCaml'ish with a JS sauce, making it really nice in many ways but also harder to pick up for JS folks. That's where Typescript clearly has the advantage; being just JS with types makes it much easier to get started, and the fact that its #huge also helps a lot. It's a bit sad as I think ReScript is much better on many fronts: the type system with crazy good inference and soundness, very easy to configure and add to existing projects (it just outputs JS files even with TS types), the module system is amazing (gone with imports) and creating simple bindings to existing JS/TS is also quite easy once you understand the basics, I'd go as far as saying it's easier than TS . It's also really fast, both the compilation as well as the JS it outputs. Because of the adoption hurtle I doubt it will be as big as TS, but I really hope it gains enough momentum and usage to just sit comfy in its niche, for that I think it needs to grow a bit further. I do think the ReScript team has made incredible progress on all fronts; I think ReScript is much easier to pick up than Reason, because of the language tweaks, but also the new website is so much better than the scattered docs in multiple places. I hope it will continue to improve and more people will give it a go!
- gdsdfe 5y agoI've never understood why reason was rebranded into rescript, it felt like it killed the momentum behind it at the time
- pbiggar 5y agoIt's because Reason and Bucklescript were two separate projects with two separate goals. The goals of Reason was to be multi-platform, which was causing lots of technical challenges for rescript, which didn't care about that need but were doing most of the work. So the two needed to split up, and no-one had ever heard of bucklescript. Then the messaging on the name change was unclear, and the fact that Reason still exists (walking dead, but the name is still out there) made it all very unclear to everyone what was happening, and I think that caused a massive amount of damage to the momentum. But then again, it's a great language that's moving quickly, so I expect it will continue to grow. Certainly my company is built on it.
- chrischen 5y agoThere is a fork of ReScript that supports ReasonML syntax and with the goal of maintaining Ocaml compatibility: https://github.com/melange-re/melange https://github.com/melange-re/melange.