Adding TypeScript

At this point, we have a fully functional Rails 7 setup to start writing front-end code. We could stop here. However, instead, we’re going to add TypeScript to our mix.

There’s good news and bad news regarding using TypeScript with esbuild.

The good news is that esbuild will convert .ts files from TypeScript to JavaScript without any configuration changes on our part. The bad news is that all esbuild does is remove TypeScript type annotations and whatever other TypeScript-only stuff might exist in the file. Specifically, esbuild does not run the TypeScript compiler to determine if the code is type-safe. Because we want to use TypeScript specifically to determine if our code is type-safe, this seems less than ideal.

What ...

Get Modern Front-End Development for Rails, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.