TypeScript MCQ questions
Take a short practice test with instant feedback, then revise every question with its answer and the reason behind it.
- Questions
- 105
- From lessons
- 85
- Your last test
- —
Practice test
What does the override keyword add?
All questions with answers
What does the TypeScript compiler output?
Show answer
Answer: B. JavaScript
TypeScript compiles (transpiles) to plain JavaScript with the types removed.
Which type accepts any value but forces you to check it before use?
Show answer
Answer: B. unknown
unknown is the type-safe counterpart of any.
What is the type of a function that always throws?
Show answer
Answer: C. never
never means the function never returns normally.
How do you mark a property as optional?
Show answer
Answer: B. name?: string
The ? after the name makes it optional (type string | undefined).
Which describes "a string or a number"?
Show answer
Answer: B. string | number
| is a union. & is an intersection; [a, b] is a tuple.
What is the type of x?
TypeScript Illustrative const x = 'hello';Show answer
Answer: B. "hello"
const with a primitive literal infers the literal type.
Which utility type makes every property optional?
Show answer
Answer: C. Partial<T>
Partial<T> maps every property to optional.
Which utility type creates a type with only some keys?
Show answer
Answer: B. Pick<T, K>
Pick keeps the listed keys; Omit removes them.
What does keyof { id: number; name: string } produce?
Show answer
Answer: A. "id" | "name"
keyof gives a union of the property names.
What error does this produce?
TypeScript Illustrative function double(n: number) { return n * 2; } double('4');Show answer
Answer: B. Type "string" is not assignable to type "number"
The parameter is typed number, so passing a string is a compile error.
Which keyword narrows a union of class instances?
Show answer
Answer: B. instanceof
instanceof checks the prototype chain; typeof works for primitives.
Which syntax declares a generic function?
Show answer
Answer: B. function id<T>(x: T): T
Type parameters go in angle brackets after the name.
What does "strict": true enable?
Show answer
Answer: B. A family of strict checks including strictNullChecks
It turns on noImplicitAny, strictNullChecks, strictFunctionTypes and more.
With strictNullChecks, can null be assigned to a string variable?
Show answer
Answer: B. No, unless the type includes null
null and undefined must be listed explicitly: string | null.
Which is true about interfaces?
Show answer
Answer: B. They can be merged by declaring them twice
Declaration merging combines interfaces with the same name; type aliases cannot merge.
What does a readonly property prevent?
Show answer
Answer: B. Reassigning it after initialisation
readonly is a compile-time check against reassignment.
Which file configures the TypeScript compiler?
Show answer
Answer: B. tsconfig.json
tsconfig.json holds compilerOptions, include and exclude.
What does Record<string, number> describe?
Show answer
Answer: B. An object with string keys and number values
Record<K, V> builds an object type from key and value types.
What is the return type of an async function that returns a number?
Show answer
Answer: B. Promise<number>
Async functions always return a promise.
Which enum alternative avoids generated JavaScript?
Show answer
Answer: B. A union of string literals
Literal unions are type-only; enums emit an object at runtime (except const enums).
What does <T extends { id: number }> mean?
Show answer
Answer: B. T can be any type that has a numeric id
extends sets a minimum shape; T may have more properties.
From the lesson: GenericsWhat happens to TypeScript types when the code is compiled?
Show answer
Answer: B. They are removed, leaving plain JavaScript
Types exist only at compile time.
From the lesson: Introduction to TypeScriptEvery valid JavaScript program is also valid TypeScript syntax.
Show answer
Answer: A. True
TypeScript is a superset of JavaScript (though type checking may report errors).
From the lesson: Introduction to TypeScriptWho created TypeScript?
Show answer
Answer: C. Microsoft
Microsoft released TypeScript in 2012.
From the lesson: Introduction to TypeScriptWhen does JavaScript usually reveal a type mistake?
Show answer
Answer: C. When the faulty line runs
JavaScript is dynamically typed.
From the lesson: JavaScript vs TypeScript