What is TypeScript?
How TypeScript can be used with WordPress
To get started with TypeScript, you’ll need to install it using one of three installation routes: npm module, NuGet package, or a Visual Studio Extension.
For this example, we’ll install TypeScript using NPM as our dependency manager. Run the following in your theme or custom plugin directory:
Npm install typescript --save-data
You’ll have to set up the JSON file so the TypeScript compiler knows where the TypeScript files are to compile. Run the following command in the same directory to create the JSON file:
Npx tsc --init
You can now change the file extensions from .js to .ts or .jsx to .tsx and start writing in TypeScript or start migrating your current code to TypeScript. When you’re ready to compile, run the following command:
Or, if you want to compile TypeScript on the fly as you’re developing, run the following:
Npx tsc --watch