Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Body should be partial #17

Open
danilofuchs opened this issue Jun 2, 2020 · 1 comment
Open

Body should be partial #17

danilofuchs opened this issue Jun 2, 2020 · 1 comment

Comments

@danilofuchs
Copy link

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];
@prabhanjansyn
Copy link

Having the same error, is it still not fixed?

universalhandle added a commit to universalhandle/event-mocks that referenced this issue Mar 8, 2021
trevor-leach added a commit to trevor-leach/event-mocks that referenced this issue Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants