Signal Forms: `validateStandardSchema` throws a TypeError for an issue whose path runs through a key the model lacks

未關閉 適合新手
#71,128 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@rene-schakmann 已經在處理了。

開始於 2026年10月3日。

  • #71153 來自 @rene-schakmann —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
78/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
angular, typescript
領域
frontend

研究方向

從 @angular/forms/signals 中 validateStandardSchema 使用的 standardIssueToFormTreeError() 實作開始,然後針對 ['ghost'] 和 ['ghost', 'name'] 執行此 issue 的最小重現。完成的標準是中間鍵的情況不再擲出例外,並在根上回報一個 Wrong. 錯誤,與未知末尾鍵的 fallback 行為一致。

由索引模型根據 Issue 內容生成。

描述

area: forms gemini-triaged
Which @angular/* package(s) are the source of the bug?

forms

Is this a regression?

No

Description

standardIssueToFormTreeError() walks an issue's path with target = target[pathKey]. For an unknown last key, target ends up undefined and the error falls back to the field the schema validates, which is fine. For an unknown key anywhere before the last one, the next step reads a property of undefined, and reading errors() throws.

import { signal } from '@angular/core';
import { form, validateStandardSchema } from '@angular/forms/signals';
import type { StandardSchemaV1 } from '@standard-schema/spec';

function reportsOn(path: PropertyKey[]): StandardSchemaV1<{ name: string }> {
  return {
    '~standard': {
      version: 1,
      vendor: 'repro',
      validate: () => ({ issues: [{ message: 'Wrong.', path }] }),
    },
  };
}

// In an injection context:
const lastKey = form(signal({ name: '' }), (p) => validateStandardSchema(p, reportsOn(['ghost'])));
lastKey().errors(); // one error, 'Wrong.', on the root

const middleKey = form(signal({ name: '' }), (p) => validateStandardSchema(p, reportsOn(['ghost', 'name'])));
middleKey().errors(); // TypeError: Cannot read properties of undefined (reading 'name')

A Standard Schema can easily report outside the bound model: a schema written for a wider object, a refinement with a computed path, a Vest test whose name is not a model key. Today one such issue makes errors() throw.

Expected: the same fallback as for an unknown last key. target = target?.[pathKey] in that loop would give it.

Minimal reproduction

The snippet above.

Exception or error

TypeError: Cannot read properties of undefined (reading 'name')

Environment

Angular CLI 22.2.0, Angular 22.2.0, Node.js 26.7.0, darwin arm64. standardIssueToFormTreeError() is the same in 22.2.1, 22.3.0-next.0 and on main.

Anything else?

No.

主要語言
TypeScript
星號
102k
分支
28.2k
平均合併
2 天 10 分鐘
30 天內合併 PR
402

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

angular/angular 的其他 Issue

查看 angular/angular 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。