Skip to content
webtype.orgwebtype.org#227 includes-tuple · par 3

    ↑↓ move · ⏎ open · esc close

    No. 227 · August 4, 2026 · Moderate

    Includes

    Implement `Includes<T, U>` so it reports whether the tuple `T` contains exactly the type `U`. `boolean` does not count as containing `true` — the match must be exact. `Equal` from the harness is in scope.

    01

    Try the puzzle yourself

    Par 3

    Puzzle

    includes-tuple.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

    4
    • Includes<[1, 2, 3], 2>
      true
    • Includes<[1, 2, 3], 4>
      false
    • Includes<[], 1>
      false
    • Includes<[boolean], true>
      false

    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 5, 2026

    The solution

    type Includes<T extends readonly unknown[], U> =
      T extends readonly [infer H, ...infer R]
        ? Equal<H, U> extends true
          ? true
          : Includes<R, U>
        : false

    The common wrong answer

    type Includes<T extends readonly unknown[], U> =
      U extends T[number] ? true : false

    Short and wrong. `T[number]` is the union of element types and `extends` asks about assignability, so `Includes<[boolean], true>` answers `true` — `true` is assignable to `boolean` even though the tuple contains no such element. Assignability is not membership.

    Line by line

    1. Equal<H, U> extends true

      `Equal` returns the type `true` or the type `false`, so it has to be tested with `extends true` rather than used directly as a condition. This is the puzzle where the harness itself becomes a tool.

    2. : false

      Reaching the empty tuple means every element was checked and none matched. Exhausting the list *is* the negative answer.

    Takeaway

    When a puzzle says "exactly", `extends` is the wrong tool — it tests assignability, which is one-directional. Exact identity needs `Equal`, and this is why every check on this site is built on it.

    Uses