Skip to content

Commit cc8a55f

Browse files
ianmacartneyConvex, Inc.
authored andcommitted
use Expand in VObject utils (#42784)
- This improves the intellisense - but is there a cost to using Expand? GitOrigin-RevId: c9731f84ca6844d9ef88dbe6bb4f9c2864e0a465
1 parent a9762ea commit cc8a55f

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/values/validators.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Expand } from "../type_utils.js";
12
import { GenericId } from "./index.js";
23
import { GenericValidator, ObjectType } from "./validator.js";
34
import { JSONValue, convexToJson } from "./value.js";
@@ -329,14 +330,14 @@ export class VObject<
329330
*/
330331
omit<K extends keyof Fields & string>(
331332
...fields: K[]
332-
): VObject<Omit<Type, K>, Omit<Fields, K>, IsOptional> {
333+
): VObject<Expand<Omit<Type, K>>, Expand<Omit<Fields, K>>, IsOptional> {
333334
const newFields = { ...this.fields };
334335
for (const field of fields) {
335336
delete newFields[field];
336337
}
337338
return new VObject({
338339
isOptional: this.isOptional,
339-
fields: newFields as Omit<Fields, K>,
340+
fields: newFields as any,
340341
});
341342
}
342343

@@ -346,14 +347,18 @@ export class VObject<
346347
*/
347348
pick<K extends keyof Fields & string>(
348349
...fields: K[]
349-
): VObject<Pick<Type, Extract<keyof Type, K>>, Pick<Fields, K>, IsOptional> {
350+
): VObject<
351+
Expand<Pick<Type, Extract<keyof Type, K>>>,
352+
Expand<Pick<Fields, K>>,
353+
IsOptional
354+
> {
350355
const newFields: Record<string, GenericValidator> = {};
351356
for (const field of fields) {
352357
newFields[field] = this.fields[field];
353358
}
354359
return new VObject({
355360
isOptional: this.isOptional,
356-
fields: newFields as Pick<Fields, K>,
361+
fields: newFields as Expand<Pick<Fields, K>>,
357362
});
358363
}
359364

@@ -383,10 +388,14 @@ export class VObject<
383388
*/
384389
extend<NewFields extends Record<string, GenericValidator>>(
385390
fields: NewFields,
386-
): VObject<Type & ObjectType<NewFields>, Fields & NewFields, IsOptional> {
391+
): VObject<
392+
Expand<Type & ObjectType<NewFields>>,
393+
Expand<Fields & NewFields>,
394+
IsOptional
395+
> {
387396
return new VObject({
388397
isOptional: this.isOptional,
389-
fields: { ...this.fields, ...fields } as Fields & NewFields,
398+
fields: { ...this.fields, ...fields } as Expand<Fields & NewFields>,
390399
});
391400
}
392401
}

0 commit comments

Comments
 (0)