TypeScript Basic Types and Type Annotations Quiz
A 40-question TypeScript quiz covering primitive types, type inference, explicit annotations, arrays, tuples, object types, unions, intersections, and literal types.
Question 1
Which of the following is NOT a TypeScript primitive type?
Question 2
What is the type of the value 42 in TypeScript?
Question 3
What type does TypeScript infer here?
const flag = true;Question 4
Which type represents extremely large integers?
Question 5
Which keyword creates a unique, immutable primitive value?
Question 6
What type is inferred?
let x = 2;Question 7
When does TypeScript apply type inference?
Question 8
What is the inferred type?
const greeting = 'hello';Question 9
Why might explicit type annotations be useful?
Question 10
What is the type of value here?
let id: string = 'abc123';Question 11
Which annotation is valid for function return types?
Question 12
What does this function return type annotation mean?
function sum(a: number, b: number): number { return a + b; }Question 13
Which syntax creates an array of numbers?
Question 14
What is the type of this array?
const list = [1, 2, 3];Question 15
What is a tuple?
Question 16
What is the type of this tuple?
const pair: [string, number] = ['age', 30];Question 17
What is structural typing?
Question 18
What type is enforced?
const user: { name: string; age: number } = { name: 'Evan', age: 20 };Question 19
How do you mark an optional property?
Question 20
What is the type of this optional property?
type Info = { title?: string };Question 21
What does a union type represent?
Question 22
What type is this variable?
let value: string | number = 'id';Question 23
What is narrowing?
Question 24
What type remains after this check?
let id: string | number = 10;
if (typeof id === 'string') {
// inside
}Question 25
What does an intersection type do?
Question 26
What type is produced by this intersection?
type A = { x: number };
type B = { y: string };
type C = A & B;Question 27
Which statement about intersections is correct?
Question 28
What is a literal type?
Question 29
Which of these is a literal type?
Question 30
What type is declared here?
let direction: 'left' | 'right';Question 31
What is the inferred type?
const status = 'ok' as const;Question 32
What is a common use of literal types?
Question 33
Which array annotation uses generic syntax?
Question 34
What is the inferred type?
const roles = ['admin', 'user'] as const;Question 35
What type describes an object with unknown keys but number values?
Question 36
What is the type of result?
const id = Math.random() > 0.5 ? 10 : 'ten';Question 37
Which describes a readonly tuple?
Question 38
What type does this infer?
let result = [1, 'a'];Question 39
Which statement about any is true?
Question 40
What does TypeScript infer for this function?
function greet() { return 'Hello'; }