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

Narrowing on a kind field

Inside case "card", which properties can you read on p without an error?

type Payment =
  | { kind: "upi"; vpa: string }
  | { kind: "card"; last4: string; network: string }

function label(p: Payment) {
  switch (p.kind) {
    case "card": /* here */
  }
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions