Skip to content
RED SAGSkills
easy5 pts · first answer countsjavascripttypescriptnarrowing

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