What is the command to install the TypeScript compiler globally using npm?
The command is npm install -g typescript. This installs the TypeScript compiler so you can use the tsc command anywhere on your computer.
Click to reveal answer
beginner
What does the tsc command do?
The tsc command runs the TypeScript compiler. It converts TypeScript files (.ts) into JavaScript files (.js) that browsers can understand.
Click to reveal answer
beginner
Why do we need to install Node.js before installing TypeScript?
Node.js provides the npm tool, which is used to install TypeScript and other packages. Without Node.js, you cannot use npm to install the TypeScript compiler.
Click to reveal answer
intermediate
What is the purpose of the tsconfig.json file in a TypeScript project?
The tsconfig.json file tells the TypeScript compiler how to compile your project. It sets options like which files to include, the JavaScript version to output, and other settings.
Click to reveal answer
beginner
How can you check if TypeScript is installed correctly on your system?
Run the command tsc --version in your terminal or command prompt. If it shows a version number, TypeScript is installed correctly.
Click to reveal answer
Which command installs TypeScript globally on your computer?
Anpm install typescript
Bnode install typescript
Ctsc install
Dnpm install -g typescript
✗ Incorrect
The correct command is npm install -g typescript to install TypeScript globally.
What file extension does TypeScript use for its source files?
A.ts
B.js
C.tsx
D.json
✗ Incorrect
TypeScript source files use the .ts extension.
What is the main purpose of the TypeScript compiler?
ATo run JavaScript code
BTo convert JavaScript to TypeScript
CTo convert TypeScript to JavaScript
DTo install Node.js
✗ Incorrect
The TypeScript compiler converts TypeScript code into JavaScript code.
Before installing TypeScript, which software must be installed first?
APython
BNode.js
CJava
DGit
✗ Incorrect
Node.js must be installed first because it provides npm, which installs TypeScript.
What command checks the installed TypeScript version?
Atsc --version
Bnpm version typescript
Cnode --version
Dtsc check
✗ Incorrect
Use tsc --version to check the installed TypeScript version.
Explain the steps to install and verify the TypeScript compiler on your computer.
Think about what tools you need and how to check if TypeScript is ready to use.
You got /3 concepts.
Describe the role of the tsconfig.json file in a TypeScript project setup.
It's like a settings file for the TypeScript compiler.
You got /3 concepts.
Practice
(1/5)
1. What command do you use to install the TypeScript compiler globally on your system?
easy
A. npm install typescript
B. tsc install
C. npm install -g typescript
D. install typescript -g
Solution
Step 1: Understand global installation
To use TypeScript compiler anywhere, it must be installed globally using npm with the -g flag.
Step 2: Identify correct npm command
The correct command is npm install -g typescript which installs TypeScript globally.
Final Answer:
npm install -g typescript -> Option C
Quick Check:
Global install uses npm install -g [OK]
Hint: Use npm install -g to install global packages [OK]
Common Mistakes:
Forgetting the -g flag for global install
Using 'tsc install' which is invalid
Installing locally without -g
2. Which of the following commands correctly compiles a TypeScript file named app.ts into JavaScript?
easy
A. tsc app.js
B. tsc app.ts
C. npm run app.ts
D. compile app.ts
Solution
Step 1: Identify the TypeScript compiler command
The TypeScript compiler command is tsc followed by the TypeScript file name.
Step 2: Match the correct file extension
We must compile the .ts file, so the command is tsc app.ts.
Final Answer:
tsc app.ts -> Option B
Quick Check:
Compile with tsc filename.ts [OK]
Hint: Use tsc followed by .ts filename to compile [OK]
Common Mistakes:
Trying to compile .js files with tsc
Using npm run instead of tsc
Typing wrong command like 'compile'
3. After installing TypeScript globally, what will be the output of the command tsc --version if the installed version is 5.1.3?
medium
A. TypeScript 5.1.3
B. tsc version: 5.1.3
C. 5.1.3
D. Version 5.1.3
Solution
Step 1: Understand tsc --version output format
The tsc --version command outputs 'TypeScript 5.1.3'.
Step 2: Match output to options
Only 'TypeScript 5.1.3' matches the exact output format.
Final Answer:
TypeScript 5.1.3 -> Option A
Quick Check:
tsc --version outputs 'TypeScript X.Y.Z' [OK]
Hint: tsc --version shows 'TypeScript X.Y.Z' [OK]
Common Mistakes:
Expecting only the version number without 'TypeScript ' prefix
Confusing output with npm version output
Adding extra text like 'Version'
4. You run tsc app.ts but get an error: tsc: command not found. What is the most likely cause?
medium
A. Node.js is not installed
B. app.ts file has syntax errors
C. You need to run npm start instead
D. TypeScript is not installed globally or PATH is not set
Solution
Step 1: Analyze the error message
The error 'tsc: command not found' means the system cannot find the TypeScript compiler command.
Step 2: Identify cause of missing command
This usually happens if TypeScript is not installed globally or the system PATH does not include the location of tsc.
Final Answer:
TypeScript is not installed globally or PATH is not set -> Option D
Quick Check:
Command not found means missing install or PATH [OK]
Hint: Check if tsc is installed globally and in PATH [OK]
Common Mistakes:
Assuming syntax errors cause command not found
Trying npm start which is unrelated
Thinking Node.js absence causes this error
5. You want to compile multiple TypeScript files in a project folder without typing each filename. Which setup helps you compile all files at once?
hard
A. Create a tsconfig.json file and run tsc without arguments
B. Run tsc *.ts in the terminal
C. Install TypeScript locally and run npm compile
D. Use tsc --all command
Solution
Step 1: Understand how to compile multiple files
TypeScript uses a tsconfig.json file to configure project compilation settings for multiple files.
Step 2: Use tsc with tsconfig.json
Running tsc without arguments reads tsconfig.json and compiles all files specified there.
Final Answer:
Create a tsconfig.json file and run tsc without arguments -> Option A