Skip to the solution
MediumFrontend11 min read

What does the 'strict' flag in tsconfig enable?

536 views

The problem

Question presented to candidate: "Most projects set strict: true in tsconfig. What does that one flag actually turn on, and what kinds of bugs does each part catch?"

What a strong answer should cover:

  • strict is an umbrella for the strict family; each member can be overridden individually
  • The members in 5.4: noImplicitAny, strictNullChecks, strictFunctionTypes, strictBindCallApply, strictPropertyInitialization, noImplicitThis, alwaysStrict, useUnknownInCatchVariables, plus strictBuiltinIteratorReturn added in 5.6
  • Why strictNullChecks and noImplicitAny matter most, with a concrete crash each one prevents
  • Details: method-syntax parameters stay bivariant, strictPropertyInitialization needs strictNullChecks, catch variables become unknown
  • What is not included (noUncheckedIndexedAccess, exactOptionalPropertyTypes) and how to roll strict out on an existing codebase

Code / implementation expected: Optional β€” one or two snippets that compile without strict and fail with it.

  • config
  • tsconfig

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

11 min read Β· 10 sections

Run the code

Edit the code and run it here. Each console line with an expected value becomes a test.

TypeScriptnoImplicitAny, strictNullChecks and unknown catch variables
TypeScriptFunction, bind/call/apply, this and class checks

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 41 of 81 in TypeScript

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

Up nextMedium

How do you fix JSX and type-only import errors under `verbatimModuleSyntax`?

Continue