Skip to content

Commit 4759f6a

Browse files
committed
fix(util-dynamodb): fix signature overload resolution for marshall() fn
1 parent bd9be23 commit 4759f6a

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

packages/util-dynamodb/src/marshall.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { AttributeValue } from "@aws-sdk/client-dynamodb";
2+
13
import { convertToAttr } from "./convertToAttr";
24
import { marshall } from "./marshall";
35

@@ -52,6 +54,26 @@ describe("marshall", () => {
5254
expect(convertToAttr).toHaveBeenCalledWith(input, undefined);
5355
});
5456

57+
it("should resolve signatures correctly", () => {
58+
// eslint-disable @typescript-eslint/no-unused-vars
59+
const ss: AttributeValue.SSMember = marshall(new Set(["a"]));
60+
const ns: AttributeValue.NSMember = marshall(new Set([0]));
61+
const bs: AttributeValue.BSMember = marshall(new Set([new Uint8Array()]));
62+
const s: AttributeValue.SMember = marshall("a");
63+
const n: AttributeValue.NMember = marshall(0);
64+
const nil: AttributeValue.NULLMember = marshall(null);
65+
const bool: AttributeValue.BOOLMember = marshall(false);
66+
const array: AttributeValue[] = marshall([]);
67+
const object: Record<string, AttributeValue> = marshall({
68+
pk: "abc",
69+
sk: "xyz",
70+
});
71+
const unrecognizedClassInstance1: Record<string, AttributeValue> = marshall(new Map());
72+
const unrecognizedClassInstance2: Record<string, AttributeValue> = marshall(new Date());
73+
const unrecognizedNonClassInstanceValue: AttributeValue.$UnknownMember = marshall(BigInt(0));
74+
// eslint-enable @typescript-eslint/no-unused-vars
75+
});
76+
5577
it("with class instance as an input", () => {
5678
class TestInputClass {
5779
constructor(private readonly a: string, private readonly b: string) {}

packages/util-dynamodb/src/marshall.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ export interface marshallOptions {
3939
export function marshall(data: Set<string>, options?: marshallOptions): AttributeValue.SSMember;
4040
export function marshall(data: Set<number>, options?: marshallOptions): AttributeValue.NSMember;
4141
export function marshall(data: Set<NativeAttributeBinary>, options?: marshallOptions): AttributeValue.BSMember;
42-
export function marshall<M extends { [K in keyof M]: NativeAttributeValue }>(
43-
data: M,
44-
options?: marshallOptions
45-
): Record<string, AttributeValue>;
46-
export function marshall<L extends NativeAttributeValue[]>(data: L, options?: marshallOptions): AttributeValue[];
4742
export function marshall(data: string, options?: marshallOptions): AttributeValue.SMember;
4843
export function marshall(data: number, options?: marshallOptions): AttributeValue.NMember;
4944
export function marshall(data: NativeAttributeBinary, options?: marshallOptions): AttributeValue.BMember;
5045
export function marshall(data: null, options?: marshallOptions): AttributeValue.NULLMember;
5146
export function marshall(data: boolean, options?: marshallOptions): AttributeValue.BOOLMember;
47+
export function marshall<L extends NativeAttributeValue[]>(data: L, options?: marshallOptions): AttributeValue[];
48+
export function marshall<M extends Record<string, NativeAttributeValue>>(
49+
data: M,
50+
options?: marshallOptions
51+
): Record<string, AttributeValue>;
5252
export function marshall(data: unknown, options?: marshallOptions): AttributeValue.$UnknownMember;
5353
export function marshall(data: unknown, options?: marshallOptions) {
5454
const attributeValue: AttributeValue = convertToAttr(data, options);

0 commit comments

Comments
 (0)