Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"check-types": "tsc -p tsconfig.check.json",
"typecheck": "tsc --noEmit"
},
"dependencies": {
Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/schema.test.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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;
Comment thread
Railly marked this conversation as resolved.
expect(spec.root).toBe("card-1");
}
});

it("validates a valid spec", () => {
const spec = {
root: "card-1",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ type InferSpecField<T, TCatalog> =
: T extends SchemaType<"propsOf", infer Path>
? InferPropsOfType<Path, TCatalog>
: T extends SchemaType<"any">
? unknown
? any
: unknown;

type InferRefType<Path, TCatalog> = Path extends "catalog.components"
Expand Down
9 changes: 9 additions & 0 deletions packages/core/tsconfig.check.json
Original file line number Diff line number Diff line change
@@ -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"]
}
Loading