Skip to content

Body should be partial #17

Description

@danilofuchs

Current type definition for createEvent is this:

declare const dictionary: {
    "aws:apiGateway": import("aws-lambda").APIGatewayProxyEvent;
};

export default function createEvent<T extends keyof typeof dictionary, B>(
  eventType: T,
  body: typeof dictionary[T],
): typeof dictionary[T];

When accessing

createEvent("aws:apiGateway", {
    body: JSON.stringify({}),
}

Which gives the following error:

Argument of type '{ body: string; }' is not assignable to parameter of type 'APIGatewayProxyEvent'.
  Type '{ body: string; }' is missing the following properties from type 'APIGatewayProxyEventBase<{ [name: string]: any; }>': headers, multiValueHeaders, httpMethod, isBase64Encoded, and 7 more.

The library merges the body with the template, so the user should be able to provide a deeply partial object.

The type definition should be:

// https://gist.github.com/navix/6c25c15e0a2d3cd0e5bce999e0086fc9
+ type DeepPartial<T> = T extends Function ? T : (T extends object ? { [P in keyof T]?: DeepPartial<T[P]>; } : T); 

export default function createEvent<T extends keyof typeof dictionary, B>(
  eventType: T,
-   body: typeof dictionary[T],
+   body: DeepPartial<typeof dictionary[T]>
): typeof dictionary[T];

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions