— What a click bait title?!?
— I know, right?
— Yeah... no
— But you can also compile TypeScript code with Babel
— I know, right?
Now it's time to dig in the small configuration required by each kind of project. It's impossible to describe them all, we'll start with the most popular ones (for me). But remember, with it actual popularity, there is plugins, modules or even core support for TypeScript in almost all libraries and framework.
First, you'll need some new dependencies to execute your TypeScript code :
Then, you'll need to change the default classic nodemon
start command in your
The only difference with your usual configuration, the executable is overrode as
ts-node instead of the default
node and your entry point is now a
.ts file. As you may understand at this point, your files will not be
.js anymore, but
.ts (obvious, I know).
Finally, you need a new
tsconfig.json file at your project's root (like in any TypeScript project) for the related configuration. Something like :
And that's it! Now your app's code will like something like:
import in Node projects without Webpack \o/
Good news if you're using react-create-app, it's already embedded in it! The only thing you must do is to use the following command :
Same difference for file extensions here,
.jsx will be transformed to
.tsx. Nothing else change from your favorite React architecture.
Because SSR is more than a trendy thing, you'll maybe also add TypeScript to your Next.js powered project. To do that, just use the official plugin with :
And follow the official recipe.
Same thing here, official plugin, great doc.
See also the official migration guide