Skip to content

Sharing attribute definitions #516

Answered by NimmLor
BoilerTom90 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, this is because the variable is of type AttributeDefinitions and the specific type is lost. There are two options to do this in a nice way.

  1. Use the as const and satisfies operator introduced in typescript 4.9
const sharedAttributes = {
   attr1: { type: 'string', required: true },
   attr2: { type: 'number', required: false },
  
   attrn: { type: 'number', required: false }
} as const satisfies AttributeDefinitions
  1. Create a generic helper type that also ensures that all properties are defined
import { type AttributeDefinition } from 'dynamodb-toolbox/dist/classes/Entity'

export type AsAttributeDefinition<
  TObject extends Record<PropertyKey, unknown>
> = Record<keyof TObject, A…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by naorpeled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants