Using Three.js with TypeScript
TypeScript provides a typed language that transpiles to JavaScript. This means that you can use it to create your site, and it’ll run just like normal JavaScript in the browser. There are many different ways of setting up a TypeScript project, but the easiest one is provided by Vite (https://vitejs.dev/). Vite provides an integrated build environment and can be seen a bit as an alternative to webpack (which we use for the normal chapter samples).
The first thing we need to do is create a new Vite project. You can do these steps yourself, or you can look in the three-ts
folder and just run yarn install
there to skip this setup. To get an empty TypeScript project with Vite, all we have to do is run the following code in the console:
$ yarn create vite three-ts --template vanilla-ts yarn create v1.22.17 warning package.json: No license field [1/4]Resolving packages... [2/4]
Fetching packages... [3/4]
Linking...