...

/

Quiz: Objects and Collections

Quiz: Objects and Collections

Put your object modeling skills to the test—from property modifiers and index signatures to arrays, tuples, and readonly structures.

We'll cover the following...
1

What error does TypeScript report for this object, defined using an index signature with a known key?

type Switches = {
  main: "on" | "off";
  [k: string]: "on" | "off" | "auto";
};

const panel: Switches = {
  main: "off",
  turbo: "auto",
  eco: "stand‑by"
};
A)

There’s no error—every property matches.

B)

There’s an error only on main because it isn’t optional.

C)

There’s an error on eco because its value isn’t allowed.

D)

There’s an error on turbo because extra keys are forbidden.

Question 1 of 50 attempted
...