event-mocks
event-mocks copied to clipboard
Body should be partial
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];
Having the same error, is it still not fixed?