Skip to content

docs(signal-forms-tutorial): update new schema syntax in example code. #62702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: prototype/signal-forms
Choose a base branch
from

Conversation

ttma1046
Copy link

@ttma1046 ttma1046 commented Jul 18, 2025

(chandlerfang@gmail.com)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

old signal form 'Schema' syntax in the example code in signal forms tutorial

What is the new behavior?

update to new signal form 'schema' function syntax in the example code in signal forms tutorial

Does this PR introduce a breaking change?

  • Yes
  • No

@pullapprove pullapprove bot requested a review from crisbeto July 18, 2025 05:48
@angular-robot angular-robot bot added the area: docs Related to the documentation label Jul 18, 2025
@ngbot ngbot bot added this to the Backlog milestone Jul 18, 2025
@ttma1046
Copy link
Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This PR correctly updates the signal forms schema syntax in the tutorial. I've found one issue in an example where a custom validation error is created as a plain object literal instead of using ValidationError.custom(). Using the factory function is safer and more aligned with the API. I've left a suggestion to fix this.

required,
validate,
} from '@angular/forms/experimental';

export const friendSchema: Schema<Friend> = (friend) => {
export const friendSchema = schema<Friend>((friend) => {
required(friend.name);
required(friend.email);
validate(friend.email, ({value}) => {
return value().includes('@') ?
undefined :
{ kind: 'emailFormat' };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The object literal { kind: 'emailFormat' } is not an instance of ValidationError. While this might work due to structural typing in some cases, it's not type-safe and goes against the intended API usage. It's best practice to use ValidationError.custom() to create custom validation errors. This ensures your code is robust and aligned with the framework's validation error handling.

For this specific case, you could also use the built-in ValidationError.email() which produces an error with kind: 'email'.

Using either ValidationError.custom() or ValidationError.email() will require importing ValidationError from @angular/forms/experimental.

Suggested change
{ kind: 'emailFormat' };
ValidationError.custom({ kind: 'emailFormat' });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: docs Related to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant