🔷

TypeScript MCQ

Test your TypeScript knowledge with 100 multiple choice questions covering fundamentals to advanced concepts, with instant feedback and explanations.

100 Questions 40 Beginner 40 Intermediate 20 Advanced
1

What is TypeScript primarily known as?

2

Which file extension is used for TypeScript files?

3

Which command compiles a TypeScript file to JavaScript using the TypeScript compiler?

4

How do you declare a variable named age of type number in TypeScript?

5

Which type represents a value that can be any type and disables type checking?

6

What does the "void" return type indicate for a function?

7

How do you define an array of strings in TypeScript?

8

What keyword is used to define a custom type alias?

9

Which symbol marks a property as optional in an interface?

10

What is the purpose of an interface in TypeScript?

11

Which of these is a valid TypeScript union type declaration?

12

What does the "readonly" modifier do to a property?

13

Which TypeScript feature allows enumerating a fixed set of named constants?

14

What is the default value of the first member in a numeric enum?

15

How do you annotate a function parameter "name" as a string?

16

Which configuration file is used to configure the TypeScript compiler options for a project?

17

What does the "never" type represent?

18

How do you specify that a function parameter is optional?

19

Which keyword is used to implement an interface in a class?

20

What is the correct syntax to create a tuple of a string and a number?

21

What does the "as" keyword do in TypeScript?

22

Which built-in utility type makes all properties of a type optional?

23

What is the output type of "typeof" used in a type context, e.g. "type T = typeof someVar"?

24

Which symbol is used for non-null assertion in TypeScript?

25

How do you define a constant variable in TypeScript that cannot be reassigned?

26

What does "strict mode" in tsconfig.json enable?

27

Which of the following correctly defines a function type?

28

What is "type inference" in TypeScript?

29

Which access modifier makes a class member accessible only within the class itself?

30

What is the default access modifier for class members in TypeScript if none is specified?

31

How do you represent a value that could be either a string or null?

32

What does "npx tsc --init" do?

33

Which of these is a primitive type in TypeScript?

34

How do you import a named export "add" from a module "math.ts"?

35

What is the purpose of the "export" keyword?

36

Which TypeScript feature lets you create a new type by extending an existing interface?

37

What does the double equals (==) versus triple equals (===) distinction inherited from JavaScript mean in TypeScript?

38

How do you define a class property with a default value in TypeScript?

39

Which loop syntax iterates over the values of an array in TypeScript?

40

What is the result type of "5 as const" assigned to a variable?

1

What is a generic function in TypeScript?

2

What does the "keyof" operator produce?

3

Given "interface Point { x: number; y: number; }", what is the type of "keyof Point"?

4

What is the purpose of mapped types like "{ [K in keyof T]: boolean }"?

5

What does the utility type "Pick<T, K>" do?

6

What does the utility type "Omit<T, K>" do?

7

What is a discriminated union in TypeScript?

8

What does "strictNullChecks" do when enabled?

9

What is the difference between an "interface" and a "type" alias for object shapes?

10

What does the following do? "function isString(val: unknown): val is string { return typeof val === 'string'; }"

11

What does "Record<K, V>" represent?

12

What is the effect of declaring a class constructor parameter as "private readonly name: string"?

13

What does the "satisfies" operator (introduced in TS 4.9) do?

14

What is the purpose of "declare" in a .d.ts file?

15

How does TypeScript handle excess property checks for object literals?

16

What does "Partial<Required<T>>" effectively do for an interface T with optional and required properties?

17

What is the result of widening for "let x = 'hello';" versus "const y = 'hello';"?

18

What does the conditional type "T extends U ? X : Y" do?

19

What is the purpose of the "infer" keyword in conditional types?

20

What does "ReturnType<typeof myFunc>" give you?

21

How do generic constraints work, e.g. "function logLength<T extends { length: number }>(arg: T)"?

22

What is the difference between "unknown" and "any"?

23

What does declaration merging allow for namespaces and interfaces with the same name?

24

What is an abstract class used for in TypeScript?

25

What does the "in" operator do as a type guard, e.g. "if ('swim' in animal)"?

26

What is the purpose of generics default type parameters, e.g. "interface Box<T = string>"?

27

How does TypeScript's structural typing differ from nominal typing?

28

What does "Exclude<T, U>" do?

29

What is "module augmentation" used for?

30

What is the effect of "noImplicitAny" compiler option?

31

What does the spread operator do when used with TypeScript tuples, e.g. "type T = [number, ...string[]]"?

32

What is the purpose of function overloads in TypeScript?

33

How does TypeScript treat enums with string values, e.g. "enum Color { Red = 'RED', Blue = 'BLUE' }"?

34

What does "this" parameter typing, e.g. "function fn(this: HTMLElement, event: Event)", accomplish?

35

What does the "Awaited<T>" utility type do?

36

When using "import type { Foo } from './module'", what is the effect?

37

What does "Array.isArray(value)" help with when narrowing a union type like "string | string[]"?

38

What is the difference between "interface A extends B" and "type A = B & C"?

39

What does the "as const" assertion do when applied to an array literal, e.g. "const arr = [1, 2, 3] as const"?

40

What is the benefit of using "unknown" as the type for a caught error in a try/catch block, e.g. "catch (err: unknown)"?

1

What is the difference between covariance and contravariance in TypeScript function parameter typing?

2

What does the following recursive conditional type compute? "type Flatten<T> = T extends Array<infer Item> ? Flatten<Item> : T"

3

What is a "branded type" (or nominal typing emulation) pattern used for?

4

Given "type DeepReadonly<T> = { readonly [K in keyof T]: T[K] extends object ? DeepReadonly<T[K]> : T[K] }", what does this mapped type achieve?

5

What is the purpose of template literal types, e.g. "type Greeting = `Hello, ${string}!`"?

6

What does "distributive conditional types" mean for "type ToArray<T> = T extends any ? T[] : never" when T is a union like "string | number"?

7

What is the role of "asserts" in a function signature like "function assertIsString(val: unknown): asserts val is string"?

8

How do variadic tuple types, e.g. "type Concat<T extends unknown[], U extends unknown[]> = [...T, ...U]", behave?

9

What does the TypeScript compiler do differently with "const enum" compared to a regular "enum"?

10

What does the "--isolatedModules" compiler flag warn against?

11

How does TypeScript resolve overload resolution order when multiple overload signatures could match a call?

12

What is the effect of "exactOptionalPropertyTypes" compiler option?

13

What does the "this" type (polymorphic this) returned from a method enable in a fluent/chainable API?

14

What is the purpose of "Function" overload combined with generic inference for a curried function, e.g. "function curry<A, B, C>(fn: (a: A, b: B) => C): (a: A) => (b: B) => C"?

15

How does TypeScript handle circular type references, e.g. "type Json = string | number | boolean | null | Json[] | { [key: string]: Json }"?

16

What does the "--strictPropertyInitialization" flag enforce for class properties?

17

What is the difference between "Function" type and a specific function signature like "(a: number) => void" for type safety?

18

What does the utility type combination "type Mutable<T> = { -readonly [K in keyof T]: T[K] }" do with the "-readonly" modifier?

19

In TypeScript's control flow analysis, what does "Object.freeze(obj)" do to the inferred type of obj's properties when obj is a literal?

20

What is "type narrowing via assignment" and how does control flow analysis use it, e.g. "let x: string | number = getValue(); x = 5;"?