Skip to content

Commit 3509d7e

Browse files
ianmacartneyConvex, Inc.
authored andcommitted
make v.nullable more explicit about needing a required value (#43112)
currently `v.nullable(v.optional(v.string()))` will "work" but if you try to assign it to a validator, you'll get a difficult to parse error like below. Instead let's have the error at the v.nullable callsite, since it needs a required value right now. ``` Type 'VUnion<{ author: string; body: string; _creationTime: number; _id: Id<"messages">; } | null | undefined, [VObject<{ author: string; body: string; _creationTime: number; _id: Id<"messages">; } | undefined, { ...; }, "optional", "_creationTime" | ... 2 more ... | "_id">, VNull<...>], "required", "_creationTime" | ... ...' is not assignable to type 'void | PropertyValidators | Validator<any, "required", any> | undefined'. Type 'VUnion<{ author: string; body: string; _creationTime: number; _id: Id<"messages">; } | null | undefined, [VObject<{ author: string; body: string; _creationTime: number; _id: Id<"messages">; } | undefined, { ...; }, "optional", "_creationTime" | ... 2 more ... | "_id">, VNull<...>], "required", "_creationTime" | ... ...' is not assignable to type 'VUnion<any, Validator<any, "required", any>[], "required", any>'. Type '[VObject<{ author: string; body: string; _creationTime: number; _id: Id<"messages">; } | undefined, { author: VString<string, "required">; body: VString<string, "required">; _id: VId<...>; _creationTime: VFloat64<...>; }, "optional", "_creationTime" | ... 2 more ... | "_id">, VNull<...>]' is not assignable to type 'Validator<any, "required", any>[]'. Type 'VNull<null, "required"> | VObject<{ author: string; body: string; _creationTime: number; _id: Id<"messages">; } | undefined, { author: VString<string, "required">; body: VString<...>; _id: VId<...>; _creationTime: VFloat64<...>; }, "optional", "_creationTime" | ... 2 more ... | "_id">' is not assignable to type 'Validator<any, "required", any>'. Type 'VObject<{ author: string; body: string; _creationTime: number; _id: Id<"messages">; } | undefined, { author: VString<string, "required">; body: VString<string, "required">; _id: VId<...>; _creationTime: VFloat64<...>; }, "optional", "_creationTime" | ... 2 more ... | "_id">' is not assignable to type 'Validator<any, "required", any>'. Type 'VObject<{ author: string; body: string; _creationTime: number; _id: Id<"messages">; } | undefined, { author: VString<string, "required">; body: VString<string, "required">; _id: VId<...>; _creationTime: VFloat64<...>; }, "optional", "_creationTime" | ... 2 more ... | "_id">' is not assignable to type 'VObject<any, Record<string, Validator<any, OptionalProperty, any>>, "required", any>'. Type '"optional"' is not assignable to type '"required"'.ts(2322) ``` GitOrigin-RevId: 74c4906c0c0495000349ccc6e84814993a9494f3
1 parent 098f0a5 commit 3509d7e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/values/validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export const v = {
226226
/**
227227
* Allows specifying a value or null.
228228
*/
229-
nullable: <T extends GenericValidator>(value: T) => {
229+
nullable: <T extends Validator<any, "required", any>>(value: T) => {
230230
return v.union(value, v.null());
231231
},
232232
};

0 commit comments

Comments
 (0)