Skip to content

Infer Post from PostSchema so the type and schema cannot diverge silently #85

@ooloth

Description

@ooloth

Why

PostSchema and the manually-maintained Post type declare incompatible blocks fields, so changes to the schema do not propagate to the type and the mismatch is invisible until a runtime failure.

Current state

io/notion/schemas/post.ts line 44–45 defines blocks: z.array(z.unknown()) in PostSchema. Line 54 declares blocks: GroupedBlock[] on the hand-written Post type. PostSchema is exported but never imported in production code, making it dead code that cannot enforce its contract.

Ideal state

  • Post is inferred directly from PostSchema via z.infer<typeof PostSchema>.
  • A single source of truth exists for the Post shape.
  • Any change to the schema is automatically reflected in the type; divergence is a compile error.

Starting points

  • io/notion/schemas/post.ts — lines 44–45 (PostSchema.blocks) and line 54 (the hand-written Post.blocks to remove)

QA plan

  1. Open io/notion/schemas/post.ts and verify Post is declared as type Post = z.infer<typeof PostSchema> rather than a hand-written interface.
  2. Change PostSchema.blocks to a stricter type — expect TypeScript to reflect the change in Post automatically.
  3. Run tsc --noEmit — expect no type errors.

Done when

Post is inferred from PostSchema and no hand-written Post interface with a separate blocks declaration exists.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions