Skip to content

Commit

Permalink
types(n4s): simplify the types for
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Nov 10, 2021
1 parent e09503d commit 13830b9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/n4s/src/modifiers/partial.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import enforce from 'enforce';
import type { TShapeObject, TLazy } from 'genEnforceLazy';

export default function partial(shapeObject: TShapeObject): TShapeObject {
const output: TShapeObject = {};
// Help needed improving the typings of this file.
// Ideally, we'd be able to extend TShapeObject, but that's not possible.
export default function partial<T extends Record<any, any>>(shapeObject: T): T {
const output = {} as T;
for (const key in shapeObject) {
output[key] = enforce.optional(shapeObject[key]) as TLazy;
output[key] = enforce.optional(shapeObject[key]) as T[Extract<
keyof T,
string
>];
}

return output;
Expand Down

0 comments on commit 13830b9

Please sign in to comment.