🔷

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

How This Practice Test Works

Every question below expands right on this page — click a question to reveal its four options, pick the one you think is correct, and you'll get instant feedback along with the correct answer and a short explanation of the reasoning. Questions are grouped by difficulty, so start with the 40 beginner questions to confirm your fundamentals, work through the 40 intermediate ones, and finish with the 20 advanced questions that mirror what exams and technical screenings actually ask. There's no sign-up, no timer, and no limit — retake the test as often as you like.

Curated by Tech Baithak Editorial Team  ·  Last updated: June 2026

1

What is TypeScript primarily known as?

B

Correct Answer

A superset of JavaScript that adds static typing

Explanation

TypeScript is a strict syntactical superset of JavaScript that adds optional static types, compiled down to plain JavaScript.

2

Which file extension is used for TypeScript files?

C

Correct Answer

.ts

Explanation

TypeScript source files use the .ts extension; .tsx is used for files containing JSX syntax.

3

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

A

Correct Answer

tsc app.ts

Explanation

The TypeScript compiler command "tsc" compiles .ts files into .js files.

4

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

A

Correct Answer

let age: number = 25;

Explanation

TypeScript uses a colon followed by the type after the variable name to annotate types.

5

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

C

Correct Answer

any

Explanation

The "any" type opts out of type checking, allowing a value to be of any type without errors.

6

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

B

Correct Answer

The function does not return a meaningful value

Explanation

void is used for functions that do not return a value, meaning their return value should not be used.

7

How do you define an array of strings in TypeScript?

A

Correct Answer

string[] or Array<string>

Explanation

TypeScript supports both string[] and the generic Array<string> syntax to describe arrays of strings.

8

What keyword is used to define a custom type alias?

C

Correct Answer

type

Explanation

The "type" keyword creates a type alias, e.g. "type ID = number | string;".

9

Which symbol marks a property as optional in an interface?

B

Correct Answer

?

Explanation

Appending "?" after a property name, like "name?: string", makes that property optional.

10

What is the purpose of an interface in TypeScript?

B

Correct Answer

To define the shape of an object

Explanation

Interfaces describe the structure (shape) that an object must conform to, purely for compile-time type checking.

11

Which of these is a valid TypeScript union type declaration?

B

Correct Answer

let id: number | string;

Explanation

The pipe symbol "|" is used to declare a union type, meaning the variable can hold either type.

12

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

B

Correct Answer

Prevents it from being reassigned after initialization

Explanation

readonly prevents a property from being reassigned after its initial assignment, enforced at compile time.

13

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

A

Correct Answer

enum

Explanation

enum defines a set of named constants, e.g. "enum Direction { Up, Down, Left, Right }".

14

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

C

Correct Answer

0

Explanation

By default, numeric enums start numbering their members from 0 unless a different value is specified.

15

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

B

Correct Answer

function greet(name: string)

Explanation

Parameter type annotations use a colon followed by the type, placed after the parameter name.

16

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

B

Correct Answer

tsconfig.json

Explanation

tsconfig.json specifies the root files and compiler options required to compile a TypeScript project.

17

What does the "never" type represent?

B

Correct Answer

A value that never occurs, such as a function that always throws

Explanation

never represents values that never occur, commonly used as the return type of functions that always throw or never finish.

18

How do you specify that a function parameter is optional?

A

Correct Answer

function greet(name?: string)

Explanation

A "?" placed after the parameter name marks it as optional, allowing the argument to be omitted.

19

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

B

Correct Answer

implements

Explanation

The "implements" keyword is used by a class to guarantee it conforms to a given interface.

20

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

A

Correct Answer

let pair: [string, number] = ["age", 25];

Explanation

Tuples in TypeScript are written using square brackets with each element type in order, e.g. [string, number].

21

What does the "as" keyword do in TypeScript?

B

Correct Answer

Performs type assertion, telling the compiler to treat a value as a specific type

Explanation

Type assertions like "value as string" tell the compiler to treat a value as a specified type without changing runtime behavior.

22

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

B

Correct Answer

Partial<T>

Explanation

Partial<T> constructs a type with all properties of T set to optional.

23

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

B

Correct Answer

The TypeScript type of that variable

Explanation

In a type context, typeof extracts the static type of a value, useful for deriving types from variables.

24

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

B

Correct Answer

!

Explanation

The "!" postfix operator asserts that a value is not null or undefined, e.g. "value!.length".

25

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

B

Correct Answer

const x: number = 5;

Explanation

TypeScript uses JavaScript's "const" keyword to declare block-scoped constants that cannot be reassigned.

26

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

B

Correct Answer

A set of stricter type-checking rules including strictNullChecks

Explanation

"strict": true enables a wide range of stricter type-checking options, such as strictNullChecks and noImplicitAny.

27

Which of the following correctly defines a function type?

A

Correct Answer

let add: (a: number, b: number) => number;

Explanation

Function types are written as parameter list followed by "=>" and the return type, e.g. (a: number, b: number) => number.

28

What is "type inference" in TypeScript?

B

Correct Answer

The compiler automatically determining a variable's type based on its value

Explanation

Type inference allows TypeScript to automatically deduce types from assigned values without explicit annotations.

29

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

C

Correct Answer

private

Explanation

private restricts access to the declaring class only; it is not accessible from subclasses or outside code.

30

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

C

Correct Answer

public

Explanation

If no access modifier is written, TypeScript class members default to public.

31

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

B

Correct Answer

string | null

Explanation

A union type "string | null" allows the variable to hold either a string value or null.

32

What does "npx tsc --init" do?

B

Correct Answer

Generates a default tsconfig.json file

Explanation

"tsc --init" creates a tsconfig.json file with default compiler options in the current directory.

33

Which of these is a primitive type in TypeScript?

B

Correct Answer

boolean

Explanation

boolean, along with string, number, null, undefined, symbol, and bigint, are TypeScript primitive types.

34

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

B

Correct Answer

import { add } from "./math";

Explanation

Named exports are imported using curly braces, e.g. "import { add } from './math';".

35

What is the purpose of the "export" keyword?

B

Correct Answer

To make a variable, function, class, or type available to other modules

Explanation

export makes declarations accessible from other files via import statements.

36

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

B

Correct Answer

extends

Explanation

An interface can use "extends" to inherit members from one or more other interfaces.

37

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

B

Correct Answer

=== checks type and value, == performs type coercion before comparing

Explanation

TypeScript inherits JavaScript equality operators: === is strict (no coercion), while == coerces operands before comparing.

38

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

A

Correct Answer

class User { name: string = "Guest"; }

Explanation

Class properties can have type annotations and default values assigned directly with "=".

39

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

B

Correct Answer

for (let item of arr)

Explanation

"for...of" iterates over the values of an iterable like an array, while "for...in" iterates over keys/indices.

40

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

C

Correct Answer

the literal type 5

Explanation

Using "as const" narrows the type to the literal value 5 instead of the broader "number" type.

1

What is a generic function in TypeScript?

B

Correct Answer

A function that works with a variety of types while preserving type relationships

Explanation

Generics, e.g. "function identity<T>(arg: T): T", allow functions to operate on multiple types while keeping type safety.

2

What does the "keyof" operator produce?

A

Correct Answer

A union of the property names (keys) of a type

Explanation

keyof T produces a union type of all the property names (string literal types) of T.

3

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

B

Correct Answer

"x" | "y"

Explanation

keyof Point evaluates to the union of the property name string literals: "x" | "y".

4

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

B

Correct Answer

To create a new type by transforming properties of an existing type

Explanation

Mapped types iterate over the keys of an existing type to produce a new type with transformed property types.

5

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

B

Correct Answer

Constructs a type by picking the set of properties K from T

Explanation

Pick<T, K> selects a subset of properties K from type T to form a new type.

6

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

B

Correct Answer

Creates a type that excludes the properties in K from T

Explanation

Omit<T, K> constructs a type by taking all properties of T and removing those listed in K.

7

What is a discriminated union in TypeScript?

A

Correct Answer

A union of types that share a common literal property used to narrow the type

Explanation

Discriminated unions use a shared literal "tag" property (e.g. kind: "circle" | "square") that lets TypeScript narrow the union in conditionals.

8

What does "strictNullChecks" do when enabled?

B

Correct Answer

Requires explicit handling of null and undefined; they are not assignable to other types unless included in a union

Explanation

With strictNullChecks, null and undefined have their own types and must be explicitly included in a type's union to be valid.

9

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

B

Correct Answer

Interfaces can be merged via declaration merging, while type aliases cannot be re-opened

Explanation

Interfaces support declaration merging (multiple declarations combine), whereas a type alias with the same name causes a duplicate identifier error.

10

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

A

Correct Answer

Defines a type guard that narrows "val" to string when it returns true

Explanation

The "val is string" return type is a user-defined type guard, narrowing the type of val within branches where the function returns true.

11

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

B

Correct Answer

An object type whose keys are of type K and values are of type V

Explanation

Record<K, V> constructs an object type with keys of type K and values of type V, e.g. Record<string, number>.

12

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

B

Correct Answer

It automatically declares and initializes a private readonly class property from the constructor parameter

Explanation

Parameter properties combine declaration and assignment: the modifier automatically creates and initializes a class member of the same name.

13

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

B

Correct Answer

Validates that an expression matches a type without changing the expression's inferred type

Explanation

satisfies checks that a value conforms to a type while preserving the more specific inferred type, unlike a type annotation which widens it.

14

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

B

Correct Answer

To describe the shape of existing JavaScript code without providing an implementation

Explanation

declare is used in ambient declaration files to describe types for code that exists elsewhere (e.g. a JS library) without generating output.

15

How does TypeScript handle excess property checks for object literals?

B

Correct Answer

It flags extra properties not defined in the target type when assigning an object literal directly

Explanation

When an object literal is assigned directly to a typed variable or parameter, TypeScript errors on properties not present in the target type.

16

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

B

Correct Answer

First makes all properties required, then makes the resulting type's properties optional again

Explanation

Utility types compose: Required<T> makes everything required, then Partial<> wraps that result to make all properties optional.

17

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

B

Correct Answer

x is inferred as "string" (widened), y is inferred as the literal type "hello"

Explanation

Mutable bindings (let/var) widen literal types to their general primitive type, while const preserves the literal type since it cannot change.

18

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

B

Correct Answer

Resolves to type X if T is assignable to U, otherwise resolves to Y

Explanation

Conditional types let you choose between two types based on a type-level assignability check, similar to a ternary at the type level.

19

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

B

Correct Answer

To extract and capture a type from within another type for reuse

Explanation

infer introduces a placeholder type variable that TypeScript fills in by inferring it from the matched type, commonly used to extract return types or array element types.

20

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

B

Correct Answer

The return type of the function myFunc

Explanation

ReturnType<T> is a utility type that extracts the return type of a function type T.

21

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

B

Correct Answer

They restrict T to types that have at least a "length" property of type number

Explanation

The "extends" clause in a generic constraint limits which types can be passed in, ensuring they have the required shape.

22

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

B

Correct Answer

unknown requires type-checking or narrowing before performing operations on it, while any bypasses all checks

Explanation

unknown is a type-safe counterpart to any: you must narrow or assert its type before using it, preventing accidental unsafe operations.

23

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

B

Correct Answer

TypeScript combines their members into a single definition

Explanation

TypeScript merges multiple declarations of the same interface (or compatible namespace/interface pairs) into one combined definition.

24

What is an abstract class used for in TypeScript?

A

Correct Answer

A class that cannot be instantiated directly and may define abstract methods to be implemented by subclasses

Explanation

Abstract classes serve as base classes that cannot be instantiated; abstract methods declared in them must be implemented by derived classes.

25

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

B

Correct Answer

Narrows the type of "animal" to ones that have a "swim" property

Explanation

The "in" operator type guard narrows a union type by checking whether a specific property exists on the object at runtime.

26

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

B

Correct Answer

If no type argument is provided when using Box, T defaults to string

Explanation

Default type parameters provide a fallback type used when the generic is referenced without an explicit type argument.

27

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

A

Correct Answer

Structural typing checks types based on their shape/members, regardless of declared name; nominal typing checks based on explicit type names

Explanation

TypeScript uses structural typing: two types are compatible if their members match, even if their declared names differ.

28

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

A

Correct Answer

Constructs a type by excluding from T all members that are assignable to U

Explanation

Exclude<T, U> filters out members of union T that are assignable to U, leaving the remaining union members.

29

What is "module augmentation" used for?

B

Correct Answer

Adding new declarations to an existing module, such as extending a third-party library's types

Explanation

Module augmentation lets you declare additional members for an existing module, often used to extend types from external libraries.

30

What is the effect of "noImplicitAny" compiler option?

B

Correct Answer

It raises an error when a variable or parameter's type cannot be inferred and would default to "any"

Explanation

noImplicitAny forces explicit typing wherever TypeScript would otherwise fall back to the implicit "any" type, improving type safety.

31

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

B

Correct Answer

It defines a tuple with a fixed first element of type number followed by zero or more strings

Explanation

Rest elements in tuple types allow a fixed prefix followed by a variable number of elements of a specified type.

32

What is the purpose of function overloads in TypeScript?

A

Correct Answer

To define multiple call signatures for a function with different parameter/return types, resolved at compile time

Explanation

Overload signatures let a single function be called in multiple type-safe ways; the implementation signature is not visible to callers.

33

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

A

Correct Answer

String enums do not auto-increment and each member must be initialized explicitly

Explanation

Unlike numeric enums, string enum members must each have a literal string value explicitly assigned; there is no auto-incrementing.

34

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

B

Correct Answer

It specifies the expected type of "this" inside the function for type-checking purposes only, without affecting the actual parameter list

Explanation

A "this" parameter is a fake parameter used only by the type checker to ensure the function is called with the correct context; it is erased in compiled output.

35

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

A

Correct Answer

Recursively unwraps the type from inside a Promise

Explanation

Awaited<T> models the type returned by awaiting a Promise, recursively unwrapping nested Promises.

36

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

B

Correct Answer

It imports Foo only for type-checking purposes; it is erased from the compiled JavaScript output

Explanation

"import type" ensures the import is purely for types and is completely removed during compilation, avoiding unnecessary runtime imports.

37

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

B

Correct Answer

It acts as a type guard, narrowing the type to string[] within the true branch

Explanation

Array.isArray is recognized by TypeScript as a type guard, narrowing the checked value to an array type inside the conditional branch.

38

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

B

Correct Answer

Both can combine type shapes, but interfaces use "extends" for inheritance while type aliases use intersection ("&") to combine types

Explanation

Interface inheritance via extends and type intersection via & both combine multiple shapes into one, though they have different merging semantics for conflicting members.

39

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

B

Correct Answer

It infers the array as a readonly tuple of literal types instead of a mutable number[]

Explanation

"as const" on an array literal produces a readonly tuple type with literal element types (readonly [1, 2, 3]) rather than the wider number[].

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)"?

A

Correct Answer

It forces you to narrow or check the type of err before accessing its properties, avoiding unsafe assumptions about the error shape

Explanation

Since TypeScript 4.4, catch clause variables can be typed as unknown, which is safer than any because it requires explicit narrowing (e.g. checking "instanceof Error") before use.

1

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

B

Correct Answer

By default (without strictFunctionTypes for method syntax), function parameters are checked bivariantly, while strictFunctionTypes enforces contravariant checking for function-typed variables

Explanation

TypeScript normally checks function parameters bivariantly for methods, but the strictFunctionTypes flag enforces sound contravariant checking for function type variables (not methods).

2

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

B

Correct Answer

It recursively unwraps nested array types until it reaches a non-array element type

Explanation

This recursive conditional type repeatedly applies itself to the inferred array element type, effectively flattening nested array types down to the base element type.

3

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

B

Correct Answer

To simulate nominal typing by adding a unique phantom property so structurally identical types are not interchangeable

Explanation

Branded types add an unused "tag" property (e.g. "& { __brand: 'UserId' }") so that otherwise structurally identical types like UserId and number are not assignable to each other.

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?

B

Correct Answer

Recursively applies readonly to all nested object properties

Explanation

This recursive mapped type applies readonly to every property and recurses into nested object types, producing a deeply immutable type.

5

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

B

Correct Answer

They allow constructing string literal types by interpolating other types into a template, enabling pattern-based string types

Explanation

Template literal types build new string literal types by combining literals with other types (often unions), useful for things like CSS property names or event names.

6

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

B

Correct Answer

The conditional distributes over each union member, producing "string[] | number[]"

Explanation

Conditional types with a naked type parameter distribute over union types, applying the conditional to each constituent separately and unioning the results.

7

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

B

Correct Answer

It is an assertion function: if it returns without throwing, TypeScript narrows val to string in subsequent code

Explanation

Assertion functions use "asserts" to tell the type checker that if the function returns normally (doesn't throw), the asserted condition holds for the rest of the scope.

8

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

B

Correct Answer

They allow spreading tuple types within other tuple types, enabling generic concatenation of tuple type parameters

Explanation

Variadic tuple types support spread elements with generic tuple types, allowing type-level operations like concatenating or manipulating tuples generically.

9

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

A

Correct Answer

const enum members are inlined at use sites and no enum object is emitted in the output by default

Explanation

const enums are completely erased during compilation; their member values are inlined directly at usage sites, avoiding the runtime object generated for regular enums.

10

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

B

Correct Answer

Code constructs that cannot be correctly compiled when each file is transpiled independently, such as re-exporting types without "export type"

Explanation

isolatedModules ensures every file can be safely transpiled in isolation (as tools like Babel or esbuild do), flagging things like non-type re-exports of types that require whole-program type information.

11

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

B

Correct Answer

It picks the first overload signature (in declaration order) that matches the call, so more specific overloads should be listed first

Explanation

TypeScript checks overload signatures in the order they are written and uses the first one that matches, so specific overloads must precede more general ones.

12

What is the effect of "exactOptionalPropertyTypes" compiler option?

B

Correct Answer

It distinguishes between a property being absent versus explicitly set to undefined when the property is marked optional

Explanation

With exactOptionalPropertyTypes, "prop?: string" means the property can be omitted entirely but cannot be explicitly assigned the value undefined unless "| undefined" is included in the type.

13

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

B

Correct Answer

It allows subclass methods returning "this" to be correctly typed as the subclass type when chained

Explanation

The polymorphic "this" type lets methods like "set()" in a builder pattern return the specific subclass type, preserving type information through chained calls on subclasses.

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"?

B

Correct Answer

It transforms a two-argument function type into a chain of single-argument functions while preserving full type information for all three type parameters

Explanation

Generic higher-order function types like this preserve the relationships between argument and return types across the curried chain, so each returned function remains fully typed.

15

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

B

Correct Answer

TypeScript supports lazily-evaluated recursive type aliases for object and array types, allowing such self-referential definitions

Explanation

TypeScript allows recursive type aliases as long as the recursive reference occurs within an object or array type (not directly in a union at the top level in a way that creates infinite expansion), enabling structures like JSON types.

16

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

A

Correct Answer

Class properties must be initialized in the constructor or have a definite assignment assertion / default value, otherwise the type must include undefined

Explanation

strictPropertyInitialization ensures that every declared instance property is either assigned in the constructor, given a default, marked with "!" (definite assignment assertion), or its type explicitly allows undefined.

17

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

B

Correct Answer

The "Function" type only guarantees a callable value (like any function), losing parameter and return type information, whereas a specific signature enforces exact call shapes

Explanation

The generic "Function" type accepts any callable but provides no information about parameters or return values, making it far less type-safe than a precise function type.

18

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

B

Correct Answer

It removes the readonly modifier from all properties of T, producing a mutable version of the type

Explanation

Mapped type modifiers can be prefixed with "-" to remove them; "-readonly" strips the readonly modifier from every property, yielding a fully mutable version of T.

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?

B

Correct Answer

Object.freeze is typed to return "Readonly<T>", making properties readonly at the type level in addition to immutable at runtime

Explanation

The standard lib typing for Object.freeze returns "Readonly<T>", so TypeScript treats the frozen object's properties as readonly going forward.

20

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

B

Correct Answer

After the assignment "x = 5", TypeScript narrows the type of x to "number" for subsequent code in that flow, based on the assigned value's type

Explanation

TypeScript's control flow analysis tracks the type of a variable through assignments, narrowing it to the type of the most recently assigned value within the reachable code path.