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 */
}
}Discussion 0
Join free to post in the discussion.
Related questions
- Block scope of letFrontend Developer
- Loose vs strict equalityFrontend Developer
- Sync code runs before promise callbacksFrontend Developer
- typeof null and arraysFrontend Developer
- Changing a property of a const objectFrontend Developer
- Numbers saved in localStorageFrontend Developer
- What fetch does on a 404Frontend Developer
- TypeScript types at runtimeFrontend Developer