Skip to content

Commit 44bdbb9

Browse files
MeAkibJeanMeche
andcommitted
docs: improve type safety in custom validator documentation
Replace `field: any` with proper SchemaPath typing in Signal Forms custom validation examples to match built-in validator patterns. fixes: angular#66887 Update adev/src/content/guide/forms/signals/validation.md Co-authored-by: Matthieu Riegler <kyro38@gmail.com>
1 parent c3229b3 commit 44bdbb9

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

adev/src/content/guide/forms/signals/validation.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,8 @@ Return an error object with `kind` and `message` when validation fails. Return `
495495
Create reusable validation rule functions by wrapping `validate()`:
496496

497497
```ts
498-
function url(field: any, options?: {message?: string}) {
499-
validate(field, ({value}) => {
498+
function url(path: SchemaPath<string>, options?: {message?: string}) {
499+
validate(path, ({value}) => {
500500
try {
501501
new URL(value());
502502
return null;
@@ -509,8 +509,8 @@ function url(field: any, options?: {message?: string}) {
509509
});
510510
}
511511

512-
function phoneNumber(field: any, options?: {message?: string}) {
513-
validate(field, ({value}) => {
512+
function phoneNumber(path: SchemaPath<string>, options?: {message?: string}) {
513+
validate(path, ({value}) => {
514514
const phoneRegex = /^\d{3}-\d{3}-\d{4}$/;
515515

516516
if (!phoneRegex.test(value())) {

0 commit comments

Comments
 (0)