Skip to content
KALANBLON
Show contents

Chapter 3 of 7 · 10 min

Quiz: type your code

Annotations, inference, unions, interfaces and narrowing: let's check that you can type your code. You need 70% correct answers, and every answer is explained.

Quiz

6 questions · pass mark: 70%

  1. 1.When does TypeScript check the types?

    One answer

  2. 2.What is the inferred type of total?

    One answer

    let total = 0;
  3. 3.With type Currency = "XOF" | "EUR", which calls does format(amount: number, c: Currency) accept? (several answers)

    Several answers possible

  4. 4.In interface Client { phone?: string }, what is the type of phone?

    One answer

  5. 5.Complete the test that narrows q to a number inside the if.

    Complete the code

    function f(q: number | string) {
      if (______ q === "number") return q.toFixed(1);
      return q.trim();
    }
  6. 6.What is const missed: never = p; for in the default of a switch?

    One answer

Your progress is saved on this device. Create a free account to keep your progress on all your devices.