tsconfig & Modules

Preview — 3 of 10 questions

What does enabling "strict": true in tsconfig.json do?

javascript
{
  "compilerOptions": {
    "strict": true
  }
}
AEnables only noImplicitAny — the most common strict option
BEnables all compiler options including noEmit and declaration
CMakes TypeScript error on all any types including library types
DEnables a group of strict type-checking options: noImplicitAny, strictNullChecks, strictFunctionTypes, strictPropertyInitialization, and more

What error does strictNullChecks catch?

javascript
// tsconfig: "strictNullChecks": true

function getUser(id: string): User | null {
  return id === "1" ? { name: "Alice" } : null;
}

const user = getUser("2");
console.log(user.name); // ?
ANo error — TypeScript trusts you won't get null
BError — user could be null, and accessing .name on null crashes at runtime
CError only if user is explicitly typed as null
DWarning only — not an error

What do these fields control?

javascript
{
  "compilerOptions": { "outDir": "./dist" },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "**/*.test.ts", "dist"]
}
Aexclude is required; include is optional
Binclude and exclude both filter the output files in outDir
Cinclude lists files to compile; exclude removes files from that set
DBoth fields accept only exact file paths, not glob patterns

Sign up free to play

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