Skip to content
RED SAG Skills
easyStudy question · answer published in TypeScript interview questions, so no pointsjavascripttypescriptnarrowing

Narrowing a union with typeof

Inside the if block, what type does TypeScript give id?

function show(id: string | number) {
  if (typeof id === "string") {
    return id.toUpperCase()
  }
  return id.toFixed(0)
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions