feat(cli): assert types for every api block with declared fields
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+13
-12
@@ -138,19 +138,20 @@ function apiBlockAssertions(
|
||||
for (const block of page.ast.dataApis) {
|
||||
if (!block.sections) continue;
|
||||
|
||||
// ssr-mode sectioned blocks can never declare a `request` (they are
|
||||
// render-time only), so they always fall back to the empty-shape
|
||||
// `Record<string, never>` below. `keyof Record<string, never>` is
|
||||
// `string`, which makes the key-exactness arm of AssertAssignable
|
||||
// evaluate to `false` unconditionally and raises TS2344 on every such
|
||||
// block regardless of whether the block author did anything wrong.
|
||||
// We choose to skip emission for both (a) any non-client-mode block,
|
||||
// since it structurally can never have a request to check, and (b) any
|
||||
// block -- client included -- that has zero declared request fields,
|
||||
// since there is nothing to assert type-safety about. This is more
|
||||
// honest about intent than emitting a vacuous/always-failing check.
|
||||
// A block with zero declared request fields would fall back to the
|
||||
// empty-shape `Record<string, never>` below. `keyof Record<string,
|
||||
// never>` is `string`, which makes the key-exactness arm of
|
||||
// AssertAssignable evaluate to `false` unconditionally and raises
|
||||
// TS2344 on every such block regardless of whether the block author
|
||||
// did anything wrong. We skip emission for any block with zero
|
||||
// declared request fields, since there is nothing to assert
|
||||
// type-safety about. This applies regardless of mode: `ssr` blocks can
|
||||
// never declare a `request` and so are always caught by this same
|
||||
// check; mode-less (`any`) and `client` blocks can declare fields and
|
||||
// get an assertion whenever they do. This is more honest about intent
|
||||
// than emitting a vacuous/always-failing check.
|
||||
const fields = [...block.sections.parameters, ...block.sections.body];
|
||||
if (block.mode !== "client" || fields.length === 0) continue;
|
||||
if (fields.length === 0) continue;
|
||||
|
||||
if (!apiContracts.includes(JSON.stringify(block.path))) {
|
||||
console.warn(
|
||||
|
||||
Reference in New Issue
Block a user