Chapter 43: TypeScript Quiz

TypeScript Quiz designed exactly as if we are sitting together in a classroom or doing a live coding session right now.

I prepared three difficulty levels:

  • Level 1 – Beginner / early intermediate (good warm-up)
  • Level 2 – Solid intermediate (most common interview / daily coding level)
  • Level 3 – Advanced / tricky (senior / library author level)

Each question has:

  • the question itself
  • 4 answer options (A/B/C/D)
  • short explanation right after (so you can learn immediately)
  • difficulty rating

You can try to answer first, then check the explanation.

Let’s start!

Level 1 – Beginner / early intermediate

Q1 What is the type of status after this line?

TypeScript

A) “active” B) string C) “active” | string D) const

Correct: A as const turns it into a literal type. Very important pattern for configs, routes, roles, variants.

Q2 What happens if you write this?

TypeScript

A) Compile error B) Runtime error C) Compiles, but age is any D) Compiles, age is ignored

Correct: A TypeScript is structurally typed → extra properties are not allowed unless you add index signature or use type assertion.

Q3 What is the type of result?

TypeScript

A) “success” | 404 B) string | number C) “success” | number D) string | 404

Correct: B TypeScript widens literals to base types unless as const is used or context forces narrowing.

Level 2 – Intermediate (most common real-world questions)

Q4 Which line causes a compile error?

TypeScript

Correct: A readonly prevents reassignment. name?: string means it can be undefined or missing. delete is allowed on optional properties. Whole object replacement is allowed.

Q5 What is the type of value inside the if block?

TypeScript

A) string | number B) string | number | null C) string & number D) never

Correct: A value == null checks both null and undefined. TypeScript narrows correctly.

Q6 Which of these is not valid syntax in modern (stage 3) decorators?

TypeScript

Correct: D Decorators are placed before the thing they decorate. function @pure is invalid syntax.

Level 3 – Advanced / tricky (senior & library level)

Q7 What is the type of result?

TypeScript

A) string | number B) string C) “hello” D) never

Correct: B satisfies narrows the type correctly while still allowing extra properties (unlike as).

Q8 Which line causes a compile error?

TypeScript

Correct: C never is the bottom type — nothing is assignable to never (except never itself).

Q9 What is printed / what error do you get?

TypeScript

A) 1 B) 2 C) 0 D) Compile error

Correct: A Function length property counts required parameters only. Optional/default parameters are not counted.

Q10 – Final tricky one

Which of these does NOT compile?

TypeScript

Correct: B as const on let makes it readonly literal — you cannot reassign.

How to use these questions effectively

  1. Try to answer without running the code first
  2. If unsure → paste into https://www.typescriptlang.org/play
  3. After seeing the answer → ask yourself: Why does TypeScript behave this way? When is this behavior useful in real code?
  4. Try to change one small thing in each question and see how the type/error changes

Which level felt most comfortable / most challenging for you? Or do you want 10 more questions at a specific difficulty?

We can continue the quiz right away 😄

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *