Skip to content

Commit e8d2588

Browse files
authored
🤖 Merge PR DefinitelyTyped#73804 [aws-lambda] Update AttributeValue definition to be compatible with the one in @aws-sdk/client-dynamodb by @KuSh
1 parent 64b0753 commit e8d2588

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

‎types/aws-lambda/test/dynamodb-tests.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DynamoDBBatchResponse, DynamoDBStreamEvent, DynamoDBStreamHandler } from "aws-lambda";
1+
import { DynamoDBBatchResponse, DynamoDBStreamEvent, DynamoDBStreamHandler, StreamRecord } from "aws-lambda";
22

33
// TODO: Update test to read all event properties, and write all result
44
// properties, like the user will.
@@ -97,6 +97,17 @@ const event: DynamoDBStreamEvent = {
9797
],
9898
};
9999

100+
const keys: StreamRecord = {
101+
Keys: {
102+
// expect error when using multiple attributes in AttributeValue type
103+
// @ts-expect-error
104+
Id: {
105+
N: "101",
106+
S: "Extra",
107+
},
108+
},
109+
};
110+
100111
const streamHandlerWithResponse: DynamoDBStreamHandler = async (event, context, callback) => {
101112
// Check result type
102113
let result: DynamoDBBatchResponse;

‎types/aws-lambda/trigger/dynamodb-stream.d.ts‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@ import { Handler } from "../handler";
33
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
44
export type DynamoDBStreamHandler = Handler<DynamoDBStreamEvent, DynamoDBBatchResponse | void>;
55

6+
// eslint-disable-next-line @definitelytyped/strict-export-declare-modifiers, @definitelytyped/no-single-element-tuple-type
7+
type Merge<T> = [{ [K in keyof T]: T[K] }][number];
8+
9+
// eslint-disable-next-line @definitelytyped/strict-export-declare-modifiers
10+
type ExclusivePropertyUnion<T, P = keyof T> = P extends any
11+
? Merge<{ [K in Extract<keyof T, P>]: T[K] } & { [K in Exclude<keyof T, P>]?: never }>
12+
: never;
13+
614
// http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_streams_AttributeValue.html
7-
export interface AttributeValue {
8-
B?: string | undefined;
9-
BS?: string[] | undefined;
10-
BOOL?: boolean | undefined;
11-
L?: AttributeValue[] | undefined;
12-
M?: { [id: string]: AttributeValue } | undefined;
13-
N?: string | undefined;
14-
NS?: string[] | undefined;
15-
NULL?: boolean | undefined;
16-
S?: string | undefined;
17-
SS?: string[] | undefined;
18-
}
15+
export type AttributeValue = ExclusivePropertyUnion<{
16+
B: string;
17+
BOOL: boolean;
18+
BS: string[];
19+
L: AttributeValue[];
20+
M: Record<string, AttributeValue>;
21+
N: string;
22+
NS: string[];
23+
NULL: boolean;
24+
S: string;
25+
SS: string[];
26+
}>;
1927

2028
// http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_streams_StreamRecord.html
2129
export interface StreamRecord {

0 commit comments

Comments
 (0)