Skip to content
webtype.orgwebtype.org

    ↑↓ move · ⏎ open · esc close

    Object shapes

    Partial

    Makes every property of an object optional, one level deep.

    What it is

    A homomorphic mapped type that adds ? to every key. Because the mapping is over keyof T for a bare type parameter, it preserves everything else it finds — readonly survives, and an array stays an array. It is the first utility most people meet and the one most often reached for when something deeper was meant.

    Examples

    • Partial<{ a: string; b: number }>
      →{ a?: string | undefined; b?: number | undefined; }
    • Partial<{ readonly a: string }>
      →{ readonly a?: string | undefined; }

      readonly survives, because the mapping is homomorphic.

    • Partial<{ a: { b: string } }>
      →{ a?: { b: string; } | undefined; }

      And b is untouched. One level, always.

    Each resolved type above was printed by TypeScript 6.0.3, not written by hand.

    What it does not do

    • It is not deep. Nested objects keep every property required, which is the single most common surprise in this list.
    • Optional is not the same as "may be undefined". Under exactOptionalPropertyTypes those are different types, and Partial produces the first.

    Takeaway

    Reach for Partial on the shape you are actually assigning, not on the whole tree. If you want the tree, you have to write the recursion yourself.