This section walks you through the baseline setup and validation of TypeScript on a Google Cloud C4A (Axion Arm64) virtual machine running SUSE Linux. The goal is to confirm that your TypeScript environment is functioning correctly, from initializing a project to compiling and executing a simple TypeScript file, ensuring a solid foundation before performance or benchmarking steps.
Before running any tests, you’ll create a dedicated project directory and initialize a minimal TypeScript environment.
Start by creating a new folder to hold your TypeScript project files:
mkdir ~/typescript-benchmark
cd ~/typescript-benchmark
This creates a workspace named typescript-benchmark in your home directory, ensuring all TypeScript configuration and source files are organized separately from system files and global modules.
Next, initialize a new Node.js project. This creates a package.json file that defines your project metadata, dependencies, and scripts:
npm init -y
To enable TypeScript to properly recognize Node.js built-in APIs (like fs, path, and process), install the Node.js type definitions package:
npm install --save-dev @types/node
You should see output similar to:
{
"name": "typescript-benchmark",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}
With the TypeScript environment configured, you’ll now perform a baseline functionality test to confirm that TypeScript compilation and execution work correctly on your Google Cloud SUSE Arm64 VM.
Create a file named hello.ts with the following content:
const greet = (name: string): string => {
return `Hello, ${name}!`;
};
console.log(greet("GCP SUSE ARM64"));
This simple function demonstrates TypeScript syntax, type annotations, and basic console output.
Use the TypeScript compiler (tsc) to transpile the .ts file into JavaScript:
tsc hello.ts
This generates a new file named hello.js in the same directory.
Now, execute the compiled JavaScript using Node.js. This step verifies that:
Execute the compiled JavaScript file:
node hello.js
You should see output similar to:
Hello, GCP SUSE ARM64
You have successfully verified that your TypeScript environment is working correctly. Next, you can proceed to TypeScript performance benchmarking to measure compilation and runtime performance on your Google Cloud Arm64 VM.