WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. Book a mock interview →
Basic 4 of 100 · TypeScript

How do you install TypeScript and compile a .ts file?

📕 Buy this interview preparation book: 100 TypeScript questions & answers — PDF + EPUB for $5

To install TypeScript and compile a .ts file, follow these steps:

1. Install Node.js: TypeScript is a superset of JavaScript and requires Node.js to work. Download and install Node.js from the following link: [https://nodejs.org/en/download/] (https://nodejs.org/en/download/)

2. Install TypeScript: After installing Node.js, open your terminal or command prompt, and type the following command to install TypeScript globally:

npm install -g typescript

3. Create a ‘.ts‘ file: Create a TypeScript file with the extension ‘.ts‘. For example, create a file named ‘example.ts‘. Add this code to the file:

function greet(name: string) {
    return 'Hello, ' + name + '!';
}

let user = 'TypeScript User';
console.log(greet(user));

4. Compile the TypeScript file: In your terminal or command prompt, navigate to the directory containing the ‘example.ts‘ file. Run the following command to compile the TypeScript file to JavaScript:

tsc example.ts

This command will generate a new file named ‘example.js‘ containing the JavaScript equivalent of your TypeScript code.

5. Execute the compiled file: Now that you have the compiled JavaScript file, you can execute it using Node.js:

node example.js

This command will return the output ‘Hello, TypeScript User!‘.

Here’s a summary of the process:

  1. Install Node.js: Download and install Node.js from https://nodejs.org/en/download/.

  2. Install TypeScript: Run npm install -g typescript in the terminal/command prompt.

  3. Create a .ts file: Create a file named example.ts with the sample TypeScript code.

  4. Compile the TypeScript file: Navigate to the directory containing the example.ts file and run tsc example.ts.

  5. Execute the compiled file: Run node example.js to see the output ‘Hello, TypeScript User!‘.

Line open Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic TypeScript interview — then scores it.
📞 Practice TypeScript →
📕 Buy this interview preparation book: 100 TypeScript questions & answers — PDF + EPUB for $5

All 100 TypeScript questions · All topics