All quizzesHard
Compiler API & References — Series 2
Preview — 3 of 10 questions
Project structure: src/index.ts, src/utils/helper.ts, and a stray scripts/build.ts (outside src/) also included via include.
javascript
{
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
}
}ACompile-time error — rootDir requires every input file (including scripts/build.ts) to be located under it; since scripts/build.ts falls outside src/, tsc rejects the configuration
BCompiles fine — outDir and rootDir only affect where individual files are emitted, never which files are allowed as input
CCompiles fine, and scripts/build.ts is simply silently skipped during compilation
DCompiles fine, and TypeScript automatically adjusts rootDir behind the scenes to also include scripts/build.ts
javascript
class Base {
greeting = 'hello';
}
class Derived extends Base {
greeting = this.computeGreeting();
computeGreeting() { return 'hi'; }
}ANo — useDefineForClassFields only affects #-prefixed private fields, never regular public ones
BYes — with useDefineForClassFields: true (the default once target is ES2022+), class fields are initialized following Object.defineProperty-based semantics, matching the true ECMAScript class fields specification; this can subtly change field-initialization timing and interaction with the constructor chain compared to the older, simpler assignment-based (this.field = value) emulation TypeScript used when the flag is false
CNo — this flag only controls whether class fields are emitted as documentation comments in the compiled output
DYes, but the difference only ever matters for static class fields, never instance fields
With preserveConstEnums: true, what changes compared to the default const enum behavior?
javascript
const enum Direction { Up, Down }
export { Direction };Aconst enum members can no longer be used inside switch statements
BAll references to enum members are still inlined as literal values everywhere, exactly like a normal const enum — nothing observable changes
CTypeScript still inlines direct references to Direction's members at their use sites (the usual const enum optimization), but additionally emits a real runtime Direction object — useful for scenarios where the enum needs to be importable and inspectable by other, separately-compiled files (such as under isolatedModules-style single-file transpilation) that can't see the inlining information the full-program compiler has
DCompile-time error — preserveConstEnums can't be combined with exporting a const enum
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.