Dynamic types for attributes array #1120
Unanswered
winseybash
asked this question in
Q&A
Replies: 1 comment
-
@winseybash You can try: const getUserRecord = async <
ATTRIBUTES extends EntityPaths<typeof UserEntity>[] | undefined = undefined
>(
userId: string,
attributes?: ATTRIBUTES
): Promise<GetItemResponse<typeof UserEntity, { attributes: ATTRIBUTES }>['Item']> => {
const response = await UserEntity.build(GetItemCommand)
.key({ userId })
.options({ attributes })
.send()
return response.Item
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I am wanting to be able to dynamically pass in attributes to a function which retrieves an entity record and have the function return type match the attributes passed in.
I have tried a number of things in Typescript around
<T>
andPick
but haven't quite managed to get something to work.If someone has any ideas I'd be hugely appreciative!
Beta Was this translation helpful? Give feedback.
All reactions