dynamodb-toolbox icon indicating copy to clipboard operation
dynamodb-toolbox copied to clipboard

Entity constructor not accepting an argument with spread operator used in attributes key

Open ryantomaselli opened this issue 4 years ago • 1 comments

I updated to version 0.3 today in a Typescript environment and all of a sudden my attributes key in my entity definition is showing that it has an error (in VS Code).

Screen Shot 2021-01-05 at 4 00 50 PM Screen Shot 2021-01-05 at 4 00 57 PM

ryantomaselli avatar Jan 06 '21 00:01 ryantomaselli

This looks like a bug, but I need to do a bit more research. Thanks for reporting.

jeremydaly avatar Jan 15 '21 15:01 jeremydaly

Hey @ryantomaselli, thanks for opening this issue.

I know this is an old issue but the following seems to be working, note that you have to use as const at the moment to make it work.

const getCommonEntityAttributes = () => {
  return {
    id: { type: 'string' },
    name: { type: 'string' },
    test: { type: 'string' }
  } as const
}

const commonEntityConfig = {
  typeAlias: 'test_et'
} as const

const TestEntity = new Entity({
  name: 'TestEntity',
  ...commonEntityConfig,
  attributes: {
	    pk: { type: 'string', partitionKey: true },
	    sk: { type: 'string', sortKey: true },
	    asd: 'string',
	    set: 'set',
	    map: 'map',
	    ...getCommonEntityAttributes()
  },
  table: TestTable
})

I'll be closing this issue for now but feel free to ping me if you need any further help.

naorpeled avatar Nov 05 '22 16:11 naorpeled