The answer is “yes,” but we need to do a couple of things to make that happen. This post will show you what to do. So let’s try usin

How to use TypeScript with React 18 alpha

submited by
Style Pass
2021-06-09 20:00:11

The answer is “yes,” but we need to do a couple of things to make that happen. This post will show you what to do.

So let’s try using the ReactDOM.createRoot API. It’s this API that opts our application in to using React 18’s new features. We’ll open up index.tsx and make this change:

If we were running JavaScript alone, this would work. Because we’re using TypeScript as well, however, we’re now confronted with an error:

This is the TypeScript compiler complaining that it doesn’t know anything about ReactDOM.createRoot. This is because the type definitions that are currently in place in our application don’t have that API defined.

We might reasonably hope that everything should work now — alas, it does not. The same error is presenting. TypeScript is not happy.

Leave a Comment