tsconfig & Modules — Series 2

Preview — 3 of 10 questions

What does target control?

javascript
{
  "compilerOptions": {
    "target": "ES2020"
  }
}
AWhich module system (CommonJS, ESNext, etc.) the compiled output uses
BWhich JavaScript language version the compiled output is written in — the compiler downlevels newer syntax (like optional chaining or class fields) to be compatible with the specified ECMAScript version
CWhich version of TypeScript itself is required to build the project
DWhich browser APIs are available for type-checking (that's what lib controls instead)

javascript
{
  "compilerOptions": {
    "module": "CommonJS"
  }
}
AControls what module syntax (require/module.exports vs. import/export) the compiled JavaScript output uses — independently of target, which instead controls the JS language version
BIs deprecated and has no effect in current versions of TypeScript
COnly affects .mjs files, not regular .ts files
DControls whether the project is treated as a monorepo with workspaces

With esModuleInterop: false, importing a CommonJS-style library that has no real ES default export can require writing this instead:

javascript
import React from "react";
ANo difference at all — esModuleInterop only affects .d.ts file generation
Bimport React from "react" always fails at compile time, regardless of this setting
Cimport * as React from "react" — esModuleInterop, when enabled, lets a default import work smoothly against CommonJS modules that don't have a genuine ES default export, avoiding the need for this namespace-import workaround
DesModuleInterop only matters for .jsx/.tsx files, never plain .ts files

Sign up free to play

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