awslabs / dynamodb-data-mapper-js

A schema-based data mapper for Amazon DynamoDB.
https://awslabs.github.io/dynamodb-data-mapper-js/
Apache License 2.0
816 stars 106 forks source link

Deserializing number field #168

Open thrixton opened 4 years ago

thrixton commented 4 years ago

I have a model as per below, when I persist it, it's all OK, I can see the numField attribute type is Number in the DynamoDB console.

export class NumTest {
  public numField: 0 | 1 | 2;
  public clientId: string;
}

However, when I query the object, and check the type with typeof, it returns object.

const result = await mapper.query(NumTest, { clientId }, options);
console.log(typeof previous.numField); // object

If I take the same object and serialize it to JSON, then deserialize it again, it is correctly typed as number.

const tRes = JSON.parse(JSON.stringify(result)));
console.log(typeof tRes.numField); // number

Question Is this expected behaviour?