From 37efde9e65ce2f926f11116a0f78f9bb9dc04c20 Mon Sep 17 00:00:00 2001 From: "k.hiro1818" Date: Sat, 20 Jun 2026 12:08:36 +0000 Subject: [PATCH 1/3] fix(auth): align SchemaShape type with sveltekit-superforms to resolve pnpm check errors Co-Authored-By: Claude Sonnet 4.6 --- docs/dev-notes/2026-06-20/plan.md | 64 +++++++++++++++++++++++++++++++ src/lib/types/auth_forms.ts | 4 +- src/lib/utils/auth_forms.ts | 6 ++- 3 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 docs/dev-notes/2026-06-20/plan.md diff --git a/docs/dev-notes/2026-06-20/plan.md b/docs/dev-notes/2026-06-20/plan.md new file mode 100644 index 000000000..327c31072 --- /dev/null +++ b/docs/dev-notes/2026-06-20/plan.md @@ -0,0 +1,64 @@ +# pnpm check 型エラー修正 + +## エラー概要 + +`pnpm check` で2件の型エラーが発生。両方とも同じ根本原因。 + +| # | ファイル | 行 | エラー箇所 | +| --- | --------------------------------------- | --- | ----------------------- | +| 1 | `src/routes/(auth)/login/+page.svelte` | 22 | `superForm(data?.form)` | +| 2 | `src/routes/(auth)/signup/+page.svelte` | 16 | `superForm(data?.form)` | + +## 原因 + +`src/lib/types/auth_forms.ts:22` で定義したローカルの `SchemaShape` と、`sveltekit-superforms` 内部の `SchemaShape` の型定義が不一致。 + +**ローカル定義(`src/lib/types/auth_forms.ts:22`):** + +```typescript +type SchemaShape = Record; // value が unknown +``` + +**ライブラリ定義(`sveltekit-superforms/dist/jsonSchema/schemaShape.d.ts`):** + +```typescript +type SchemaShape = { [K in string]: SchemaShape }; // value が SchemaShape(再帰的) +``` + +`Record` → `Record` への代入は不可(`unknown` ⊅ `SchemaShape`)。 +そのため `AuthForm.shape` が `SuperValidated.shape` と互換にならず、`superForm()` の引数で型エラーになる。 + +## 修正内容(2箇所) + +### 1. `src/lib/types/auth_forms.ts:22` — 型定義をライブラリに合わせる + +```diff +- type SchemaShape = Record; ++ type SchemaShape = { [K in string]: SchemaShape }; +``` + +### 2. `src/lib/utils/auth_forms.ts:167-168` — shape リテラルを修正 + +型定義を再帰型にしたことで、`{ type: 'string' }` が `SchemaShape` に適合しなくなった(`string` ≠ `SchemaShape`)。 + +`SchemaShape` はフィールドが配列/オブジェクトかを示すツリー構造。単純な文字列フィールド(`username`, `password`)には空オブジェクト `{}` が正しい値。 + +```diff + shape: { +- username: { type: 'string' }, +- password: { type: 'string' }, ++ username: {}, ++ password: {}, + }, +``` + +## 出典 + +- **SchemaShape の型定義**: ライブラリのソースコード `node_modules/sveltekit-superforms/dist/jsonSchema/schemaShape.d.ts` および [GitHub: sveltekit-superforms/src/lib/jsonSchema/schemaShape.ts](https://github.com/ciscoheat/sveltekit-superforms/blob/main/src/lib/jsonSchema/schemaShape.ts) +- **プリミティブフィールドが shape に含まれない挙動**: 同ソースの `_schemaShape()` 実装(34行目: `return info.types.includes('array') || info.types.includes('object') ? {} : undefined;`)。公式ドキュメントには記載なし。 + +## 検証 + +```bash +pnpm check # 0 ERRORS 確認済み +``` diff --git a/src/lib/types/auth_forms.ts b/src/lib/types/auth_forms.ts index 7cecc61fc..7fde5e132 100644 --- a/src/lib/types/auth_forms.ts +++ b/src/lib/types/auth_forms.ts @@ -19,7 +19,9 @@ export type AuthFormConstraints = { password?: FieldConstraints; }; -type SchemaShape = Record; +// Must match the recursive SchemaShape from sveltekit-superforms (dist/jsonSchema/schemaShape.d.ts) +// Record is semantically equivalent but triggers TS circular reference error. +type SchemaShape = { [K in string]: SchemaShape }; /** * Represents the state and data structure for authentication forms. diff --git a/src/lib/utils/auth_forms.ts b/src/lib/utils/auth_forms.ts index 3e387b3f4..186b86f6e 100644 --- a/src/lib/utils/auth_forms.ts +++ b/src/lib/utils/auth_forms.ts @@ -164,9 +164,11 @@ const createBaseAuthForm = () => ({ pattern: '(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\\d)[a-zA-Z\\d]{8,128}', }, }, + // Primitive fields get empty objects; only arrays/objects produce nested shape nodes. + // See: sveltekit-superforms/src/lib/jsonSchema/schemaShape.ts (_schemaShape) shape: { - username: { type: 'string' }, - password: { type: 'string' }, + username: {}, + password: {}, }, }); From abac128ab64763cc85d3930882b8b6f82adad3b4 Mon Sep 17 00:00:00 2001 From: "k.hiro1818" Date: Sat, 20 Jun 2026 12:09:24 +0000 Subject: [PATCH 2/3] docs(dev-notes): remove completed pnpm check type error investigation note Co-Authored-By: Claude Sonnet 4.6 --- docs/dev-notes/2026-06-20/plan.md | 64 ------------------------------- 1 file changed, 64 deletions(-) delete mode 100644 docs/dev-notes/2026-06-20/plan.md diff --git a/docs/dev-notes/2026-06-20/plan.md b/docs/dev-notes/2026-06-20/plan.md deleted file mode 100644 index 327c31072..000000000 --- a/docs/dev-notes/2026-06-20/plan.md +++ /dev/null @@ -1,64 +0,0 @@ -# pnpm check 型エラー修正 - -## エラー概要 - -`pnpm check` で2件の型エラーが発生。両方とも同じ根本原因。 - -| # | ファイル | 行 | エラー箇所 | -| --- | --------------------------------------- | --- | ----------------------- | -| 1 | `src/routes/(auth)/login/+page.svelte` | 22 | `superForm(data?.form)` | -| 2 | `src/routes/(auth)/signup/+page.svelte` | 16 | `superForm(data?.form)` | - -## 原因 - -`src/lib/types/auth_forms.ts:22` で定義したローカルの `SchemaShape` と、`sveltekit-superforms` 内部の `SchemaShape` の型定義が不一致。 - -**ローカル定義(`src/lib/types/auth_forms.ts:22`):** - -```typescript -type SchemaShape = Record; // value が unknown -``` - -**ライブラリ定義(`sveltekit-superforms/dist/jsonSchema/schemaShape.d.ts`):** - -```typescript -type SchemaShape = { [K in string]: SchemaShape }; // value が SchemaShape(再帰的) -``` - -`Record` → `Record` への代入は不可(`unknown` ⊅ `SchemaShape`)。 -そのため `AuthForm.shape` が `SuperValidated.shape` と互換にならず、`superForm()` の引数で型エラーになる。 - -## 修正内容(2箇所) - -### 1. `src/lib/types/auth_forms.ts:22` — 型定義をライブラリに合わせる - -```diff -- type SchemaShape = Record; -+ type SchemaShape = { [K in string]: SchemaShape }; -``` - -### 2. `src/lib/utils/auth_forms.ts:167-168` — shape リテラルを修正 - -型定義を再帰型にしたことで、`{ type: 'string' }` が `SchemaShape` に適合しなくなった(`string` ≠ `SchemaShape`)。 - -`SchemaShape` はフィールドが配列/オブジェクトかを示すツリー構造。単純な文字列フィールド(`username`, `password`)には空オブジェクト `{}` が正しい値。 - -```diff - shape: { -- username: { type: 'string' }, -- password: { type: 'string' }, -+ username: {}, -+ password: {}, - }, -``` - -## 出典 - -- **SchemaShape の型定義**: ライブラリのソースコード `node_modules/sveltekit-superforms/dist/jsonSchema/schemaShape.d.ts` および [GitHub: sveltekit-superforms/src/lib/jsonSchema/schemaShape.ts](https://github.com/ciscoheat/sveltekit-superforms/blob/main/src/lib/jsonSchema/schemaShape.ts) -- **プリミティブフィールドが shape に含まれない挙動**: 同ソースの `_schemaShape()` 実装(34行目: `return info.types.includes('array') || info.types.includes('object') ? {} : undefined;`)。公式ドキュメントには記載なし。 - -## 検証 - -```bash -pnpm check # 0 ERRORS 確認済み -``` From ed8d46902aab98a48e8a682e3c066ad720cf227b Mon Sep 17 00:00:00 2001 From: "k.hiro1818" Date: Sat, 20 Jun 2026 12:16:28 +0000 Subject: [PATCH 3/3] fix(test): update auth_forms test fixtures to match corrected SchemaShape values Co-Authored-By: Claude Sonnet 4.6 --- src/test/lib/utils/auth_forms.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/lib/utils/auth_forms.test.ts b/src/test/lib/utils/auth_forms.test.ts index 2309d9fbd..1cc277acf 100644 --- a/src/test/lib/utils/auth_forms.test.ts +++ b/src/test/lib/utils/auth_forms.test.ts @@ -27,8 +27,8 @@ vi.mock('$lib/zod/schema', () => ({ authSchema: { _type: 'ZodObject', shape: { - username: { type: 'string' }, - password: { type: 'string' }, + username: {}, + password: {}, }, }, })); @@ -129,8 +129,8 @@ describe('auth_forms', () => { }, }, shape: { - username: { type: 'string' }, - password: { type: 'string' }, + username: {}, + password: {}, } as unknown, message: '', } as unknown as SuperValidated, string>; @@ -205,8 +205,8 @@ describe('auth_forms', () => { expect(result.form.shape).toBeDefined(); expect(result.form.shape).toEqual({ - username: { type: 'string' }, - password: { type: 'string' }, + username: {}, + password: {}, }); });