File size: 768 Bytes
f76c374 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | /**
* Compile-time guard for BillingPaymentMethod.
*
* There is nothing to run here — the point is that `tsc` accepts this file.
* An earlier revision typed the fallback arm's `kind` as `string & {}`, which
* makes the discriminant non-literal and silently defeats narrowing for every
* arm: the `pm.brand` read below stops compiling. Keeping this file honest
* keeps `kind` narrowable.
*/
import type { BillingPaymentMethod } from './billing-types'
export function describePaymentMethod(pm: BillingPaymentMethod): string {
switch (pm.kind) {
case 'card':
return pm.wallet ? `${pm.wallet} ${pm.brand} ${pm.last4}` : `${pm.brand} ${pm.last4}`
case 'link':
return pm.email ?? 'Link'
case 'unknown':
return pm.raw_kind
}
}
|