typesense / typesense/typesense-js

Return value of collection `update` method seems mis-typed

Open
#150 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
569
Forks
99
Avg merge
5h 6m
Merged PRs (30d)
2

Description

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)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the typesenseClient.collections(collectionName).update({ fields: updateFields }) entry point and compare its declared return type with the JSON response shown. Done means the update return type accurately represents the returned fields object; no specific source file or test is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.