Bird
Raised Fist0
Denoframework~20 mins

TypeScript support out of the box in Deno - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Deno TypeScript Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
1:30remaining
What is the output of this Deno TypeScript code?
Consider this Deno script using TypeScript features. What will it print when run with deno run?
Deno
const greet = (name: string): string => `Hello, ${name}!`;
console.log(greet("Deno"));
ASyntaxError at compile time
BHello, undefined!
CTypeError at runtime
DHello, Deno!
Attempts:
2 left
💡 Hint
Think about how Deno runs TypeScript files directly without separate compilation.
❓ component_behavior
intermediate
1:30remaining
How does Deno handle TypeScript imports without extensions?
In Deno, what happens if you import a TypeScript module without specifying the file extension?
Deno
import { add } from "./math";
console.log(add(2, 3));
AThrows an error because Deno requires explicit file extensions
BLooks for './math.js' only and fails if not found
CAutomatically resolves to './math.ts' and runs successfully
DRuns but ignores the imported module
Attempts:
2 left
💡 Hint
Deno is strict about file extensions in imports.
📝 Syntax
advanced
2:00remaining
Which option correctly uses TypeScript enums in Deno?
Select the code snippet that compiles and runs correctly in Deno with TypeScript enums.
A
enum Color { Red, Green, Blue }
console.log(Color[1]);
B
enum Color { Red = 'red', Green = 'green', Blue = 'blue' }
console.log(Color[1]);
C
enum Color { Red, Green, Blue }
console.log(Color.Green);
D
enum Color { Red, Green, Blue }
console.log(Color['Yellow']);
Attempts:
2 left
💡 Hint
Remember how numeric and string enums behave in TypeScript.
🔧 Debug
advanced
2:00remaining
What error does this Deno TypeScript code produce?
Analyze this code and select the error it raises when run with deno run:
Deno
function multiply(a: number, b: number): number {
  return a * b;
}

console.log(multiply(5, "3"));
ASyntaxError: Unexpected string in function call.
BTypeError: Argument of type 'string' is not assignable to parameter of type 'number'.
CRuntime error: Cannot multiply number and string.
DNo error, prints 15.
Attempts:
2 left
💡 Hint
Consider TypeScript's static type checking before runtime.
🧠 Conceptual
expert
2:30remaining
How does Deno achieve TypeScript support out of the box?
Which statement best explains how Deno runs TypeScript code without manual compilation steps?
ADeno transpiles TypeScript to JavaScript internally using a built-in compiler before execution.
BDeno converts TypeScript to Python code and then executes it.
CDeno runs TypeScript files directly using the V8 engine without any transpilation.
DDeno requires a separate tsc compilation step before running TypeScript files.
Attempts:
2 left
💡 Hint
Think about how Deno integrates TypeScript support seamlessly.

Practice

(1/5)
1. What is a key feature of Deno regarding TypeScript support?
easy
A. Deno does not support TypeScript at all.
B. Deno requires manual compilation of TypeScript before running.
C. Deno runs TypeScript files directly without extra setup.
D. Deno only supports JavaScript, not TypeScript.

Solution

  1. Step 1: Understand Deno's TypeScript handling

    Deno is designed to run TypeScript files directly without needing a separate compilation step.
  2. Step 2: Compare options with this feature

    Only Deno runs TypeScript files directly without extra setup. correctly states this direct support; others contradict this fact.
  3. Final Answer:

    Deno runs TypeScript files directly without extra setup. -> Option C
  4. Quick Check:

    Direct TypeScript execution = A [OK]
Hint: Remember: Deno runs TS files without compiling first [OK]
Common Mistakes:
  • Thinking Deno needs manual TypeScript compilation
  • Believing Deno only supports JavaScript
  • Confusing Deno with Node.js setup
2. Which of the following is the correct way to run a TypeScript file named app.ts using Deno?
easy
A. deno compile app.ts
B. tsc app.ts && deno run app.js
C. node app.ts
D. deno run app.ts

Solution

  1. Step 1: Identify Deno command to run TS files

    Deno uses deno run to execute TypeScript files directly.
  2. Step 2: Evaluate other options

    deno compile app.ts compiles but does not run; tsc app.ts && deno run app.js compiles manually then runs JS, which is unnecessary; node app.ts uses Node.js which can't run TS directly.
  3. Final Answer:

    deno run app.ts -> Option D
  4. Quick Check:

    Run TS file with 'deno run' = C [OK]
Hint: Use 'deno run' to execute TypeScript files directly [OK]
Common Mistakes:
  • Trying to compile TS manually before running
  • Using Node.js command for TS files
  • Confusing compile and run commands
3. Given this TypeScript code run with Deno:
function greet(name: string) {
  return `Hello, ${name}!`;
}
console.log(greet(42));

What will happen when you run deno run on this file?
medium
A. It throws a type error before running
B. It prints 'Hello, 42!'
C. It prints 'Hello, undefined!'
D. It runs but logs 'Hello, 42!' with a warning

Solution

  1. Step 1: Analyze TypeScript type checking

    The function expects a string, but 42 is a number, causing a type error.
  2. Step 2: Understand Deno's behavior

    Deno checks types before running and will throw an error, stopping execution.
  3. Final Answer:

    It throws a type error before running -> Option A
  4. Quick Check:

    Type mismatch causes error = A [OK]
Hint: Type errors stop Deno before running code [OK]
Common Mistakes:
  • Assuming Deno runs code ignoring type errors
  • Thinking it prints with warnings
  • Confusing runtime errors with type errors
4. You wrote this TypeScript code:
const add = (a: number, b: number) => a + b;
console.log(add('5', 10));

When running with Deno, you get an error. What is the best fix?
medium
A. Remove type annotations from the function.
B. Change '5' to 5 (number) in the function call.
C. Run with Node.js instead of Deno.
D. Ignore the error and run anyway.

Solution

  1. Step 1: Identify the type mismatch

    The function expects numbers, but '5' is a string, causing a type error.
  2. Step 2: Fix the argument type

    Changing '5' (string) to 5 (number) matches the expected types and fixes the error.
  3. Final Answer:

    Change '5' to 5 (number) in the function call. -> Option B
  4. Quick Check:

    Correct argument types fix errors = B [OK]
Hint: Match argument types to function parameters [OK]
Common Mistakes:
  • Removing types loses safety
  • Trying to run with Node.js without compiling
  • Ignoring errors instead of fixing types
5. You want to write a Deno script that reads a JSON file and ensures the data matches a TypeScript interface before processing. Which approach best uses Deno's TypeScript support out of the box?
hard
A. Define the interface, read the file, parse JSON, and use a type assertion to check the data.
B. Write JavaScript code and manually check types at runtime with if statements.
C. Compile the TypeScript to JavaScript first, then run with Deno.
D. Use a third-party tool to convert JSON to TypeScript types before running.

Solution

  1. Step 1: Use TypeScript interface for type safety

    Defining an interface helps TypeScript check data structure during development.
  2. Step 2: Read and parse JSON, then assert type

    Parsing JSON and using a type assertion leverages Deno's built-in TypeScript support to catch errors early.
  3. Final Answer:

    Define the interface, read the file, parse JSON, and use a type assertion to check the data. -> Option A
  4. Quick Check:

    Use interfaces and assertions for type safety = D [OK]
Hint: Use interfaces and type assertions with Deno's TS support [OK]
Common Mistakes:
  • Ignoring TypeScript interfaces and relying on runtime checks
  • Compiling manually before running with Deno
  • Overcomplicating with external tools unnecessarily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard