EduFlow
Advanced TypeScript Patterns

Checkpoint: Types as a Design Tool

Five questions on this section. Answer all of them, then see your score and why each answer is right or wrong.

Question 1 of 5

A reviewer worries that the card number reaches saveAddress. What is true?

TypeScript
type Address = { line1: string; city: string };
function saveAddress(a: Address) { /* sends a to the address service */ }
const form = { line1: '12 Nile St', city: 'Cairo', cardNumber: '4242 4242 4242 4242' };
saveAddress(form);
Question 2 of 5

quantityInStock is null while stock is being checked and 0 when an item is sold out. Which change makes this label correct?

TypeScript
function stockLabel(quantityInStock: number | null): string {
  if (!quantityInStock) return 'Checking stock…';
  return quantityInStock === 0 ? 'Sold out' : `${quantityInStock} left`;
}
Question 3 of 5

Cartwheel adds payments. A pending payment has no capture id; a captured one always has captureId; a refunded one always has captureId, refundedAt and refundCents. Which type makes the impossible combinations fail to compile?

Question 4 of 5

What is ShippingMethod?

TypeScript
const SHIPPING_FEES = { standard: 499, express: 1299 } satisfies Record<string, number>;
type ShippingMethod = keyof typeof SHIPPING_FEES;
Question 5 of 5

A switch (order.status) has case 'canceled': with one L, and it never matches. Which change turns that typo into a compile error?

5 questions unanswered