Home > Web Front-end > JS Tutorial > body text

ReScript is not there yet

Patricia Arquette
Release: 2024-10-02 14:18:30
Original
313 people have browsed it

As a fan of ML-inspired languages, I always found ReScript intriguing. With async-await now recently added to the language, is it time for ReScript to shine?

It sure looks enticing:

... you can pick up ReScript and access the vast JavaScript ecosystem and tooling as if you've known ReScript for a long time1

Doesn't force you to search for pre-made binding libraries made by others. ReScript doesn't need the equivalent of TypeScript's DefinitelyTyped.2

What's the goal of this project?
​We aim to provide the best typed language experience for the JavaScript platform.3

Wow, so they provide the best typed language experience for the JavaScript platform, all without the need for pre-made bindings! Let's give it a go!

We quickly hit a wall as we attempt to do the most basic thing possible:

ReScript is not there yet

Hmm.. why is getElementById not on document? What's the type of document?

ReScript is not there yet

This picture is all the ReScript documentation has to say about it. No definition of Dom.document. F12 leads us down a chain of empty type definitions, so Dom.document does look like a simple alias for the JS document, nothing more.

Wait, so I do need pre-made bindings? What happened to "Doesn't force you to search for pre-made binding libraries made by others"?

Enter the rescript-webapi npm package, Bindings to the DOM and other browser-specific web APIs.. I follow the instructions and compiler errors, including one telling me I might have a configuration issue in "bsconfig.json", even though this file is now called "rescript.json". I get that working eventually.

Here's how it looks:

let elem = document->Document.getElementById("id")
// For the uninitiated, -> is the pipe operator.
// a->foo means foo(a)
// a->foo(b) means foo(a, b)
// The above code is therefore equivalent to
let elem = Document.getElementById(document, "id")
Copy after login

You'll notice that document. will bring up no code completion, as it's still basically untyped. I have to know what module and module function to call.

So the IDE won't help me type the right thing, but will it give me good information about the function I'm calling? Not really:

ReScript is not there yet

For reference, here's TypeScript out of the box:

ReScript is not there yet

Informative error, link to examples, detailed type definition. Thank you. This saves me time, effort, teaches me right as I type - this is one of the main reasons I like static typing. I'm just not getting this with ReScript.

If interacting with the DOM - the reason why JavaScript was created - is not deemed important enough to warrant built-in bindings, I think I've seen enough.

Is ReScript ready in 2024? No. Its official documentation makes lofty promises that seem outright misleading. I guess ReScript can be useful if you will write a lot of ReScript code that mostly interacts with other ReScript code. But one cannot simply ignore "the vast JavaScript ecosystem". Imagine F# without support for the BCL. Luckily, F# and its tooling were designed to consume C# types and documentation seamlessly. Surely there must be a way to leverage DefinitelyTyped in ReScript. Until ReScript does this, I don't think it can seriously compete with TypeScript.

The above is the detailed content of ReScript is not there yet. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!