TypeScript MCQs - Classes, Enums, Modules and tsconfig (Set 3)

TypeScript MCQs - Classes, Enums, Modules and tsconfig (Set 3) - CodingHumans

Set 3 moves from types to the features and compiler settings you use in real projects: classes and access modifiers, abstract classes, enums and the tsconfig options interviewers like to ask about. Each answer tells you what happens at compile time and what is left at runtime.

How to practise: read each question and tap the option you think is correct. You will see right away whether you got it, along with a short explanation, and your score is tracked at the bottom of the screen. This set has 15 questions.

TypeScript MCQ series: Set 1 | Set 2 | Set 3 | Interview Preparation Hub

Topics covered in this set

  • private, protected, readonly and #private fields
  • Parameter properties and abstract classes
  • implements and override
  • Numeric, string and const enums
  • strict, target, lib and module settings
  • Declaration files and skipLibCheck

TypeScript MCQs with answers and explanations

Q1. What is the difference between TypeScript's private modifier and a JavaScript #private field?

a) There is no difference

b) #private only works in interfaces

c) private is enforced at runtime, #private is not

d) private is checked only at compile time, while #private is enforced by the JavaScript runtime

Q2. What does this constructor do?

class User {
  constructor(private name: string) {}
}

a) Causes a compile error

b) Declares a private property name and assigns the argument to it

c) Creates a static property

d) Nothing, because the body is empty

Q3. Which statement about abstract classes is true?

a) They are the same as interfaces

b) They cannot be instantiated, and subclasses must implement their abstract members

c) They cannot have implemented methods

d) They can be instantiated with new

Q4. Where can a protected member be accessed?

a) Only in the same file

b) Anywhere

c) Inside the declaring class and its subclasses

d) Only inside the declaring class

Q5. What does implements do when a class implements an interface?

a) It copies the interface's methods into the class

b) It makes all members public automatically

c) It checks that the class satisfies the interface, without changing the class's types

d) It creates a runtime check

Q6. What is the value of Dir.Down?

enum Dir { Up, Down, Left, Right }

a) 0

b) undefined

c) "Down"

d) 1

Q7. For the numeric enum above, what does Dir[0] return?

a) A compile error

b) "Up"

c) 0

d) undefined

Q8. What is special about a const enum?

a) Its members are inlined at use sites and no enum object is emitted

b) It can be modified at runtime

c) It is the same as Object.freeze

d) Its values cannot be numbers

Q9. What does the override keyword do (especially with noImplicitOverride enabled)?

a) Marks a method that overrides a base class method, so the compiler reports an error if the base method does not exist

b) Changes the method to abstract

c) Prevents subclasses from overriding

d) Makes a method static

Q10. Which statement about the strict compiler option is correct?

a) It only enables strictNullChecks

b) It turns on a family of checks including strictNullChecks, noImplicitAny and strictFunctionTypes

c) It makes the output use "use strict" only

d) It disables type inference

Q11. What is the difference between target and lib in tsconfig?

a) target only affects declaration files

b) target controls the JavaScript syntax version that is emitted; lib controls which built-in type declarations are available

c) lib controls the output folder

d) They are the same option

Q12. What does the noEmit option do?

a) Emits only .d.ts files

b) Runs type checking without writing JavaScript output

c) Disables all errors

d) Deletes old build output

Q13. What does declaration: true do?

a) Declares global variables

b) Generates .d.ts type declaration files next to the JavaScript output

c) Allows var declarations

d) Turns on strict mode

Q14. What does esModuleInterop enable?

a) Using CommonJS modules with default import syntax, such as import express from "express"

b) Disabling module resolution

c) Running TypeScript in the browser

d) Writing ES modules in .json files

Q15. Why do many projects set skipLibCheck: true?

a) To disable lib settings

b) To skip type checking of declaration (.d.ts) files, which speeds up compilation and avoids errors in third-party types

c) To skip installing libraries

d) To skip type checking of their own code

Quick revision notes

  • private and protected only work at compile time. A #field stays private at runtime too.
  • Parameter properties declare and assign in one step.
  • Numeric enums map both ways, string enums do not, and const enums are inlined.
  • target decides the JavaScript syntax you get. lib decides which built-in types you can use.
  • noEmit only checks types. declaration creates .d.ts files. skipLibCheck skips checking .d.ts files.

Frequently asked questions

Should I use enums or union types?

Many teams prefer string literal unions because they add no code at runtime. Enums help when you need a real object to loop over, or a reverse mapping.

Is TypeScript private enough for real privacy?

No. It only blocks access in TypeScript code. If privacy at runtime matters, use #private fields.

What tsconfig settings should a new project start with?

A common start is strict: true, a modern target, moduleResolution that matches your bundler or Node, and skipLibCheck: true.

Comments

Answered 0/0Correct 0