deno-slack-api icon indicating copy to clipboard operation
deno-slack-api copied to clipboard

Potential typing issue with datastore API

Open filmaj opened this issue 2 years ago • 1 comments

Need to reproduce as a first step!

But, as reported in a feedback session by a community developer, with the following datastore:

export const OldestCodeReviewDatastore = DefineDatastore({
  name: 'code_review_datastore',
  attributes: {
    id: {
      type: Schema.types.string
    },
    timestamp: {
      type: Schema.types.string
    }
  },
  primary_key: 'id'
})

This code apparently returns an any type.

async function getOldestReview(client: SlackAPIClient, channel: string) {
  const oldestReview = await client.apps.datastore.get<typeof OldestCodeReviewDatastore.definition>({
    datastore: 'code_review_datastore',
    id: 'oldest_review_' + channel
  })

  if (!oldestReview.ok) {
    console.log('Error during request apps.datastore.get!', oldestReview)
    return '0'
  }

  return oldestReview?.item?.timestamp ?? '0'
}

filmaj avatar Jul 14 '23 17:07 filmaj

This does seems correct our typeahead for datastores is not as capable as the one found for input parameters in functions

Screenshot 2023-07-14 at 3 11 18 PM
Screenshot 2023-07-14 at 3 11 38 PM

Where with input functions we properly predict the type

Screenshot 2023-07-14 at 3 14 11 PM

WilliamBergamin avatar Jul 14 '23 19:07 WilliamBergamin