Home > Software engineering >  Property 'ExclusiveStartKey' does not exist on type '{ TableName: any; }'
Property 'ExclusiveStartKey' does not exist on type '{ TableName: any; }'

Time:05-11

I am trying to scan a DynamoDB table which may be more than 1 MB, so I'm using ExclusiveStartKey. I've been going through all the examples in How to fetch/scan all items from `AWS dynamodb` using node.js but I'm getting an error in this line: scanParams.ExclusiveStartKey = items.LastEvaluatedKey;

src/services/DynamoDB.ts:33:18 - error TS2339: Property 'ExclusiveStartKey' does not exist on type '{ TableName: any; }'.

33       scanParams.ExclusiveStartKey = items.LastEvaluatedKey;
                    ~~~~~~~~~~~~~~~~~


Found 1 error.

This kind of makes sense because the scanParams usually have just the table name and no other keys. So, how do I get rid of this error?

CodePudding user response:

Hint the shape of params to Typescript:

const params = {
  TableName: tableName,
  ExclusiveStartKey: undefined, // <-- add this
};

Or, if you want to get really fancy, import and use the library's defined type. If you are using the doc client from SDK v3, for example:

import {ScanCommandInput} from '@aws-sdk/lib-dynamodb'

const params: ScanCommandInput = {
  TableName: tableName,
};
  • Related