Rebasely Beta: data may be purged

justintypescript-ultra-strict Public

TypeScript · 32 lines · 930 B · at eb4a6ea

export type CartItem = { sku: string; unitPriceCents: number; quantity: number };export type Coupon =  | { kind: "percent"; percent: number }  | { kind: "fixed"; amountCents: number; minSubtotalCents?: number };export type CartTotal = { subtotalCents: number; discountCents: number; totalCents: number };export type CartErrorKind = "invalid_item" | "unknown_coupon" | "coupon_not_applicable";export class CartError extends Error {  /** Set for "invalid_item". */  readonly index?: number;  /** Set for "unknown_coupon" and "coupon_not_applicable". */  readonly code?: string;  constructor(    public readonly kind: CartErrorKind,    detail: { index?: number; code?: string } = {},  ) {    super(kind);    Object.assign(this, detail);  }}/** Throws CartError. */export function cartTotal(  items: CartItem[],  couponCode: string | undefined,  coupons: Record<string, Coupon>,): CartTotal {  // TODO}