From 754f9bbb6ebb4c570747a050b756a9987e1a3651 Mon Sep 17 00:00:00 2001 From: Vitaly Budovski Date: Wed, 25 Dec 2024 19:19:42 +1100 Subject: [PATCH] fix: Type errors --- paseri-lib/src/schemas/object.ts | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/paseri-lib/src/schemas/object.ts b/paseri-lib/src/schemas/object.ts index 01cb26b..5795dd8 100644 --- a/paseri-lib/src/schemas/object.ts +++ b/paseri-lib/src/schemas/object.ts @@ -12,7 +12,7 @@ type ValidShapeType = NonEmptyObject<{ type Mode = 'strip' | 'strict' | 'passthrough'; -class ObjectSchema> extends Schema> { +class ObjectSchema>> extends Schema> { private readonly _shape: Map>; private _mode: Mode = 'strict'; @@ -165,11 +165,12 @@ class ObjectSchema> extends Schema>( other: ObjectSchema, - // @ts-expect-error FIXME: How do we get the shape validation to play nicely with Merge? ): ObjectSchema> { - // @ts-expect-error FIXME: How do we get the shape validation to play nicely with Merge? - const merged = new ObjectSchema>( - Object.fromEntries([...this._shape.entries(), ...other._shape.entries()]), + const merged = new ObjectSchema( + Object.fromEntries([...this._shape.entries(), ...other._shape.entries()]) as Merge< + ShapeType, + ShapeTypeOther + >, ); merged._mode = other._mode; @@ -177,21 +178,23 @@ class ObjectSchema> extends Schema( ...keys: Keys - // @ts-expect-error FIXME: How do we get the shape validation to play nicely with Pick? ): ObjectSchema>> { - // @ts-expect-error FIXME: How do we get the shape validation to play nicely with Pick? - return new ObjectSchema>>( - Object.fromEntries(this._shape.entries().filter(([key]) => keys.includes(key as keyof ShapeType))), + return new ObjectSchema( + Object.fromEntries(this._shape.entries().filter(([key]) => keys.includes(key as keyof ShapeType))) as Pick< + ShapeType, + TupleToUnion + >, ); } omit( // Ensure at least one key remains in schema. ...keys: IsEqual, keyof ShapeType> extends true ? never : Keys - // @ts-expect-error FIXME: How do we get the shape validation to play nicely with Omit? ): ObjectSchema>> { - // @ts-expect-error FIXME: How do we get the shape validation to play nicely with Omit? - return new ObjectSchema>>( - Object.fromEntries(this._shape.entries().filter(([key]) => !keys.includes(key as keyof ShapeType))), + return new ObjectSchema( + Object.fromEntries(this._shape.entries().filter(([key]) => !keys.includes(key as keyof ShapeType))) as Omit< + ShapeType, + TupleToUnion + >, ); } }