Look at all the pretty facades!

Mark "Justin" Waks
2 min readMar 19, 2019

--

A Scala.js pointer today, instead of Dotty. I just came across the ScalablyTyped repo today, and I have to say, this is one of the most exciting Scala.js developments in months.

To understand why, you have to understand the relationship of Scala.js and JavaScript. JS is the native language of the browser, so more or less everything running in the browser has to be written in it. Scala.js is an alternate compiler backend, which compiles Scala code and spits out highly-optimized JavaScript. (The UI of my own company, Querki, is written entirely in Scala.js.)

This works very well, and Scala.js is in theory interoperable with all JS libraries. But there’s a small snag: Scala is a strongly-typed language, and JS very much isn’t. So in order to use a native-JS library from Scala, you need to write a facade — a strongly-typed description of this library’s data structures and entry points.

Mind, writing facades is pretty easy: if the library is well-documented, you can often toss off enough of a facade for your needs in a few minutes. But it’s still a barrier to entry, and folks who are new to Scala.js sometimes freak out at the notion of having to write a facade for somebody else’s library.

We’re not the only community with this problem, though. In particular, the TypeScript compiler works much the same way as the Scala.js one, and the language is focused on this particular use case. So the TS community has spent years writing TypeScript facades for an enormous number of JS libraries, including more or less all of the important ones.

The ScalablyTyped project is the latest, and from the look of things by far the most thorough, attempt to leverage all of that work. Since the TS community has already built strongly-typed facades for most of JavaScript, ScalablyTyped is in turn taking those facades and translating them into Scala.

It’s very early days yet — they’re explicitly a little ways away from a stable release— but wow, that’s already one heck of a repo. They already cover almost 6500 JS libraries, totaling over six million lines of code.

Very neat stuff! Assuming it stabilizes well, I suspect this is going to become a bedrock component of the Scala.js ecosystem in the future. Check it out…

--

--

Mark "Justin" Waks
Mark "Justin" Waks

Written by Mark "Justin" Waks

Lifelong programmer and software architect, specializing in online social tools and (nowadays) Scala. Architect of Querki (“leading the small data revolution”).

No responses yet