Skip to content

Commit de8de38

Browse files
committed
Support interface type
Signed-off-by: moznion <moznion@mail.moznion.net>
1 parent c807187 commit de8de38

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

tests/transformer.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,24 @@ describe('dynamodb record transform', () => {
265265
expect(record['kvMapToBigint']).toEqual({ M: { bigint: { N: '890' } } });
266266
expect(Object.keys(record)).toHaveLength(6);
267267
});
268+
269+
test('interface', () => {
270+
interface Interface {
271+
readonly id: number;
272+
readonly name: string;
273+
readonly tags: Map<string, string>;
274+
}
275+
const record: Record<string, AttributeValue> = dynamodbRecord<Interface>({
276+
id: 12345,
277+
name: 'John Doe',
278+
tags: new Map<string, string>([
279+
['foo', 'bar'],
280+
['buz', 'qux'],
281+
]),
282+
});
283+
expect(record['name']).toEqual({ S: 'John Doe' });
284+
expect(record['tags']).toEqual({ M: { foo: { S: 'bar' }, buz: { S: 'qux' } } });
285+
expect(record['id']).toEqual({ N: '12345' });
286+
expect(Object.keys(record)).toHaveLength(3);
287+
});
268288
});

transformer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ function visitNode(node: ts.Node, program: ts.Program): ts.Node | undefined {
8585

8686
const propName = prop.name;
8787

88-
if (prop.valueDeclaration.kind !== ts.SyntaxKind.Parameter) {
89-
const msg = `unexpected error: a property "${propName}" of the type "${typeName}" doesn't have parameter kind`;
88+
if (
89+
prop.valueDeclaration.kind !== ts.SyntaxKind.Parameter &&
90+
prop.valueDeclaration.kind !== ts.SyntaxKind.PropertySignature
91+
) {
92+
const msg = `a property "${propName}" of the type "${typeName}" doesn't have parameter kind; maybe the ${typeName} is not class of interface`;
9093
if (shouldLenientTypeCheck) {
9194
warn(msg);
9295
return undefined;

0 commit comments

Comments
 (0)