diff --git a/packages/core/package.json b/packages/core/package.json index 93f6cb51..c542a3bb 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -47,6 +47,7 @@ "scripts": { "build": "tsup", "dev": "tsup --watch", + "check-types": "tsc -p tsconfig.check.json", "typecheck": "tsc --noEmit" }, "dependencies": { diff --git a/packages/core/src/schema.test.ts b/packages/core/src/schema.test.ts index 9629de1a..2f567892 100644 --- a/packages/core/src/schema.test.ts +++ b/packages/core/src/schema.test.ts @@ -1,6 +1,7 @@ import { describe, it, expect } from "vitest"; import { z } from "zod"; import { defineSchema, defineCatalog } from "./schema"; +import type { Spec } from "./types"; // ============================================================================= // Shared test schema (mirrors the React schema shape) @@ -565,6 +566,21 @@ describe("catalog.validate", () => { actions: {}, }); + it("returns data assignable to Spec", () => { + const result = catalog.validate({ + root: "card-1", + elements: { + "card-1": { type: "Card", props: { title: "Hello" }, children: [] }, + }, + }); + expect(result.success).toBe(true); + if (result.success && result.data) { + // s.any() fields such as `visible` must not infer as unknown. + const spec: Spec = result.data; + expect(spec.root).toBe("card-1"); + } + }); + it("validates a valid spec", () => { const spec = { root: "card-1", diff --git a/packages/core/src/schema.ts b/packages/core/src/schema.ts index e5aa0bf4..a5e954dd 100644 --- a/packages/core/src/schema.ts +++ b/packages/core/src/schema.ts @@ -355,7 +355,7 @@ type InferSpecField = : T extends SchemaType<"propsOf", infer Path> ? InferPropsOfType : T extends SchemaType<"any"> - ? unknown + ? any : unknown; type InferRefType = Path extends "catalog.components" diff --git a/packages/core/tsconfig.check.json b/packages/core/tsconfig.check.json new file mode 100644 index 00000000..d7993566 --- /dev/null +++ b/packages/core/tsconfig.check.json @@ -0,0 +1,9 @@ +{ + // Type-checks the tests that assert inferred types. The full core + // project is not type-checked in CI yet. + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": true + }, + "include": ["src/schema.test.ts"] +}