0
0
Typescriptprogramming~20 mins

Running TypeScript with ts-node - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ts-node Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output when running this TypeScript code with ts-node?

Consider the following TypeScript code snippet. What will be printed to the console when you run it using ts-node?

Typescript
const greet = (name: string): string => {
  return `Hello, ${name}!`;
};

console.log(greet("Alice"));
AHello, Alice!
Bgreet is not defined
CHello, undefined!
DSyntaxError: Unexpected token
Attempts:
2 left
💡 Hint

Think about how arrow functions and template strings work in TypeScript and JavaScript.

🧠 Conceptual
intermediate
1:30remaining
Which command runs a TypeScript file directly using ts-node?

You want to run a TypeScript file named app.ts without compiling it first. Which command should you use?

Anpm run app.ts
Bnode app.ts
Ctsc app.ts && node app.js
Dts-node app.ts
Attempts:
2 left
💡 Hint

Remember, ts-node runs TypeScript files directly without manual compilation.

🔧 Debug
advanced
2:30remaining
What error occurs when running this code with ts-node?

Look at this TypeScript code. When run with ts-node, what error will it produce?

Typescript
function add(a: number, b: number): number {
  return a + b;
}

console.log(add(5, "3"));
ASyntaxError: Unexpected string
BArgument of type 'string' is not assignable to parameter of type 'number'
CNo error, output is 8
DTypeError: Cannot add number and string
Attempts:
2 left
💡 Hint

Think about TypeScript's type checking during execution with ts-node.

📝 Syntax
advanced
2:00remaining
Which option causes a syntax error when run with ts-node?

Identify which code snippet will cause a syntax error when executed with ts-node.

A
const z: string = 'hello
console.log(z);
B
const x: number = 10;
console.log(x);
C
function foo() { return 42; }
console.log(foo());
D
let y = 5
console.log(y);
Attempts:
2 left
💡 Hint

Look carefully at string literals and missing characters.

🚀 Application
expert
3:00remaining
How many items are in the resulting array after running this code with ts-node?

Consider this TypeScript code run with ts-node. How many elements does the result array contain?

Typescript
const numbers = [1, 2, 3, 4, 5];
const result = numbers.map(n => {
  if (n % 2 === 0) {
    return n * 2;
  }
});
console.log(result);
A0
B3
C5
D2
Attempts:
2 left
💡 Hint

Remember how map works and what happens when a function returns undefined.