Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return value of collection update method seems mis-typed #150

Open
aberkow opened this issue Feb 14, 2023 · 0 comments
Open

Return value of collection update method seems mis-typed #150

aberkow opened this issue Feb 14, 2023 · 0 comments

Comments

@aberkow
Copy link

aberkow commented Feb 14, 2023

Description

The return value of client().collection('name').update() seems to be mis-typed.

Steps to reproduce

data sent as JSON from postman to the proxy endpoint I'm working on

{
    "collectionName": "test",
    "updateFields": [
        {
            "name": "third_field",
            "type": "string"
        }
    ]
}
// snippet from my project

  const { 
    body: { 
      collectionName,
      updateFields
    } 
  } = req

typesenseClient.collections(collectionName)
    .update({ fields: updateFields })
      // the `update` response seems typed incorrectly relative to what's actually returned
      .then(update => {
        res.status(200).json({
          data: {
            collection: update,
            message: `Collection ${collectionName} updated`
          }
        })
      }).catch(err => {
        return serverError(res, 400, `Thee was an error updating the fields for ${collectionName}`, err)
      })

this is a screenshot of how typescript/vscode interprets the returned value of update
Screenshot of typescript definition of the update property

response object from the endpoint which appears to be of type CollectionFieldSchema or perhaps CollectionFieldUpdateSchema

{
    "data": {
        "collection": {
            "fields": [
                {
                    "facet": false,
                    "index": true,
                    "infix": false,
                    "locale": "",
                    "name": "fourth_field",
                    "optional": true,
                    "sort": false,
                    "type": "string*"
                }
            ]
        },
        "message": "Collection test updated"
    }
}

Expected Behavior

The return type of update should match what's actually returned

Actual Behavior

It doesn't 🙂

Metadata

Typesense Version:
typesense-js 1.5.2
typesense server 0.23.1 (running in docker)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant