Skip to content
webtype.orgwebtype.org#247 omit-by-type · par 3

    ↑↓ move · ⏎ open · esc close

    No. 247 · August 30, 2026 · Moderate

    Omit by type

    Implement `OmitByType<T, U>` so it drops every property of `T` whose value type is assignable to `U`, and keeps the rest exactly as they were.

    01

    Try the puzzle yourself

    Par 3

    Puzzle

    omit-by-type.ts
    Stroke 1 of 3Not run yet

    Replace ??? — your solution is checked against the cases below. Tab indents; press Escape then Tab to move focus out.

    Checks

    3
    • OmitByType<{ a: string; b: number; c: string }, string>
      { b: number }
    • OmitByType<{ a: string }, string | number>
      {}
    • OmitByType<{ a: 1; b: 2 }, never>
      { a: 1; b: 2 }

    How a check is judged Exact type equality, not assignability — an intersection is not the same as the flattened object.

    How everyone did

    Fewer than 5 people have solved this one so far. The distribution appears once there is enough of a sample to mean anything.

    Short game

    Fewest characters

    No public scores yet.

    Archive
    02

    Annotated solution

    Published August 31, 2026

    The solution

    type OmitByType<T, U> = { [K in keyof T as T[K] extends U ? never : K]: T[K] }

    The common wrong answer

    type OmitByType<T, U> = { [K in keyof T]: T[K] extends U ? never : T[K] }

    This filters the value and leaves the key standing. `a` is still there, now typed `never` — a property nobody can ever supply a value for, which is not the same thing as a property that does not exist. Filtering on the value side can empty a key; it cannot delete one.

    Line by line

    1. as T[K] extends U ? never : K

      The `as` clause renames the key being produced. Renaming it to `never` is the one way to make a mapped type emit no property at all for that iteration.

    2. OmitByType<{ a: 1; b: 2 }, never>

      Nothing is dropped here, because `1 extends never` is false. `never` is the empty set: no type is assignable to it, so no key matches and everything survives.

    Takeaway

    Keys are removed in the key clause, never in the value clause. If you find yourself producing `never` as a property type, you almost certainly meant to produce no property.

    Uses