Decorators & Project Setup — Series 2

Preview — 3 of 10 questions

With noFallthroughCasesInSwitch: true, what happens?

javascript
function describe(n: number): string {
  switch (n) {
    case 1:
      console.log("one");
    case 2:
      return "one or two";
    default:
      return "other";
  }
}
ANo effect — this option only applies to if/else chains, not switch statements
BCompile-time error on the case 1: block, because it doesn't end with a break, return, throw, or similar — control would otherwise silently "fall through" into case 2:
CRuntime error the first time describe(1) is actually called
DThe switch statement is automatically rewritten by the compiler to insert an implicit break

With noPropertyAccessFromIndexSignature: true, what happens to dict.foo?

javascript
interface Dictionary {
  [key: string]: string;
}
function getValue(dict: Dictionary) {
  return dict.foo;
}
ANo effect — this option only restricts bracket notation (dict["foo"]), not dot notation
Bdict.foo throws a runtime error, since foo was never explicitly declared as a key
CCompile-time error — dot notation (dict.foo) is disallowed for a property that only exists via an index signature; dict["foo"] must be used instead, making it visually explicit that the property comes from a dynamic/uncertain source rather than a known, declared one
Ddict.foo is automatically inferred as never

javascript
// tsconfig.json
{
  "compilerOptions": { "composite": true },
  "references": [{ "path": "../shared" }]
}
Acomposite marks a project as buildable as a dependency of other TypeScript projects (enabling incremental, cross-project builds); references declares that this project depends on ../shared, letting tsc --build compile dependencies in the correct order and reuse their build outputs
Breferences is purely documentation for humans — it has no effect on how tsc actually compiles the project
Ccomposite and references only work when using a monorepo tool like Nx or Turborepo — they don't function with plain tsc
Dreferences entirely replaces the need for include/exclude in the project's configuration

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.