Skip to content

TypeScript interview prep

A mix of multiple-choice and code-based questions to check how well you know TypeScript at a senior level.

#

What is the main difference between type and interface?

#

Which utility type extracts the parameter types of a function?

#

What does satisfies do?

#

What is a discriminated union?

#

Which of these is a valid way to define an object that is readonly?

#

What is the purpose of as const?

#

What does infer do inside a conditional type?

#

Which keyword turns a function parameter type guard into a user-defined type guard?

#

What is the structural type system?

#

Which of the following cannot be used to narrow unknown?

#

What is a mapped type?

#

What does keyof produce?

#

Which built-in utility removes a set of keys from a type?

#

What is the difference between Exclude and Omit?

#

When would you use NoInfer<T>?

#

What is an assertion signature?

#

What does this in a function type parameter do?

#

What is the result of NonNullable<string | null | undefined>?

#

Which of the following best describes a branded type?

Code quiz

#

What is the inferred type of value?

const config = {
  host: 'localhost',
  port: 3000,
} as const

const value = config.port
#

Does this code compile? If it does, what does it print?

function logLength(x: string | number) {
  if (typeof x === 'string') {
    console.log(x.length)
  } else {
    console.log(x.toFixed(2))
  }
}

logLength(42)
#

What is wrong with this generic constraint?

function getLength<T extends { length: number }>(x: T) {
  return x.length
}

console.log(getLength(42))
#

What is the type of result?

type Action =
  | { type: 'increment'; value: number }
  | { type: 'decrement'; value: number }
  | { type: 'reset' }

function isReset(action: Action): action is { type: 'reset' } {
  return action.type === 'reset'
}

const action: Action = { type: 'reset' }
const result = isReset(action)
#

What does this conditional type resolve to?

type Item<T> = T extends (infer E)[] ? E : never

type X = Item<string[]>