If you've spent any amount of time developing with JavaScript you have probably found it difficult to maintain a large code base and avoid runtime ...
For further actions, you may consider blocking this person and/or reporting abuse
Sounds great. How is the VScode-integration of ReScript? Can wen enable syntax checks while typing?
There's an incremental type-checking recently added in the VSCode extension. You can enable it by adding this in your VSCode settings:
Great article, thank you!
How would ReScript deal with pure Javascript code? Assume you have a large number of libraries. Ideally I would like to incrementally add type annotations to the code, while untouched code is still running.
Is this expectation too idealistic?
ReScript has a way to bind to any JS library or file: rescript-lang.org/docs/manual/late...
It's pretty easy to do once you grok the concept, and it's much simpler than JS interop in other languages like Elm or F#.
You would convert over one file at a time, or even split out functions or components into a new file. I've migrated over a couple projects and I've found it easy to start with the smaller parts of an app, like hooks and functions, and the work up to components. The ReScript code can have bindings to the JS code, and the JS code can import from the compiled ReScript.
I did a walkthrough here if you want to see an example: dev.to/jderochervlk/converting-a-j...
But how much changes would a library need to migrate from JS to ReS? As far as I understood native code should be widely compatible with ReScript?
It depends, but unlike TypeScript it's more of a process than renaming the file and seeing it compile. I tend to make rescript file to start moving over a component or functions into one by one and importing those functions back into JS land as I go.
My steps are usually:
I've done a half dozen migrations from JS/TS to ReScript and it usually takes me a day of work, one took me 3 days because it was really 2 websites with a heavy dependency on external libraries that were a pain to create types and bindings for.
I've always been really satisfied once I have a project running on Rescript.
I've also converted many thousands of lines of non-strict typescript to strict typescript, and I can say that the migration is much easier to move to ReScript.
Thank you for your valuable feedback. It seems, it´s more than just adding some type declarations. Some of the JS concepts (specially the ES6-module system) are really quirky, so it is probably a good decision to go in a different direction.
I´m just not too happy about what might happen in the future. JS will keep on moving, so it is an important question if a language like ReScript (and even typescript) can keep up with this development. It's easy to get onto a dead track if JS does some bigger steps.
The majority of what I've done with ReScript has been ESM compatible with Vite and node 20. The good thing about working in a language that compiles to JS is that if something in JS changes, it doesn't mean your rescript code has to change. The compiler can always be updated to output different JS if needed.
One of the things that makes JS a terrible language to work with, but a great runtime target, is that nothing ever gets removed or deprecated from the language. So if your JS or Rescript works today, it will work in the future.
Only twice as fast as TypeScript? Does not sound right to me, but it of course extremely depends on what dependencies you have installed because some really tend to bring the (turing-complete) type system of TS to its limits.
This is with 32k TypeScript vs 50k rescript, so it's more than twice as fast. It's not that complicated of a typescript project, just react and some basic libraries. I have a small typescript project with a couple thousand files that takes almost 5 minutes to type check because it has a lot of overloaded function declarations and generic types.
You can optimize typescript to be fast by doing things like making sure functions have return types, but it's something you have to really work at. ReScript is just fast out of the box.
Full builds taking half the time TypeScript does is great, but the biggest win to me is gradual type checking while I work being almost instant. I can open up a file in VSCode and see type hints the moment I hover around the code. I save and get feedback about a broken type in another file in under a second.
Is it currently possible to use data-attributes inside JSX in Rescript?
Yes. There are a few already available in rescript-react like
<div dataTestId="foo" />
which compiles out to<div data-testid="foo"/>
.If you want something custom you do have to define a custom JSX transform with the data-atrributes you want to have with the types they accept. You can do this per file, or ideally you'll want to do it once for an entire project.
Here's a forum post with some details on how to set it up: forum.rescript-lang.org/t/custom-d...
Dart exports to js
look like php lol -> omg