Decorators & Project Setup — Series 3

Preview — 3 of 10 questions

javascript
// noImplicitOverride: true
class Base {
  greet(): string { return "hi"; }
}

class Child extends Base {
  greet(): string { return "yo"; }
}
ACompiles fine — the flag only warns when override is used on a member the base does not have
BCompiles fine — noImplicitOverride applies to properties, not methods
CCompile-time error — with the flag on, a member that overrides a base member must be marked override
DCompile-time error — Child may not narrow the return type of greet

javascript
// package.json
{ "type": "module" }

// tsconfig.json
{ "compilerOptions": { "module": "node16", "moduleResolution": "node16" } }
AA compile-time error — under node16, an ESM file must use a fully specified relative path including the .js extension
BCompiles fine — TypeScript always resolves extensionless relative imports
CCompiles fine, but the emitted JavaScript rewrites the path to ./helper.js
DA compile-time error — module: "node16" may not be combined with "type": "module"

What does the emitted JavaScript import?

javascript
import type { User } from "./models";
import { logger } from "./logger";

export function greet(u: User): void {
  logger.info(u.name);
}
ABoth ./models and ./logger
BNeither — TypeScript removes all imports it can prove are unused at runtime
COnly ./models
DOnly ./logger — an import type statement is erased entirely, so ./models is never even loaded at runtime

Sign up free to play

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