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

context.params & context.data typed any for MongoDBService #3485

Open
thomasarbona opened this issue May 11, 2024 · 0 comments
Open

context.params & context.data typed any for MongoDBService #3485

thomasarbona opened this issue May 11, 2024 · 0 comments

Comments

@thomasarbona
Copy link

thomasarbona commented May 11, 2024

Steps to reproduce

On a fresh feathersjs app, generate a new service using MongoDB then check out the typings of the data and params properties (possibly more) within context, in a hook for example:

after: {
      all: [
        (context) => {
          context.params; // any
          context.data; // any
        }
      ]
    },

context.params and context.data are typed any.

It seems that the issue came from this two types in @feathersjs/feathers/lib/declarations.d.ts:

export type ServiceGenericData<S> = S extends ServiceInterface<infer _T, infer D> ? D : any;
export type ServiceGenericParams<S> = S extends ServiceInterface<infer _T, infer _D, infer P> ? P : any;

MongoDBService doesn't extends ServiceInterface.

Possible fix

I managed to fix the problem by adding this prototype to MongoDBService in @feathersjs/mongodb/lib/index.d.ts, idk if it can break something:

update(id: NullableId, data: Data, params?: ServiceParams): Promise<Result>;

Expected behavior

Correct typings for context properties.

System configuration

Here is the dependencies:

 "dependencies": {
    "@feathersjs/adapter-commons": "^5.0.25",
    "@feathersjs/authentication": "^5.0.25",
    "@feathersjs/authentication-client": "^5.0.25",
    "@feathersjs/authentication-local": "^5.0.25",
    "@feathersjs/authentication-oauth": "^5.0.25",
    "@feathersjs/configuration": "^5.0.25",
    "@feathersjs/errors": "^5.0.25",
    "@feathersjs/express": "^5.0.25",
    "@feathersjs/feathers": "^5.0.25",
    "@feathersjs/mongodb": "^5.0.25",
    "@feathersjs/schema": "^5.0.25",
    "@feathersjs/socketio": "^5.0.25",
    "@feathersjs/transport-commons": "^5.0.25",
    "@feathersjs/typebox": "^5.0.25",
    "compression": "^1.7.4",
    "mongodb": "^6.5.0",
    "winston": "^3.13.0"
  },
  "devDependencies": {
    "@feathersjs/cli": "5.0.25",
    "@feathersjs/rest-client": "^5.0.25",
    "@types/mocha": "^10.0.6",
    "@types/node": "^20.12.8",
    "axios": "^1.6.8",
    "cross-env": "^7.0.3",
    "mocha": "^10.4.0",
    "nodemon": "^3.1.0",
    "prettier": "^3.2.5",
    "shx": "^0.3.4",
    "ts-node": "^10.9.2",
    "typescript": "^5.4.5"
  }
smngvlkz added a commit to smngvlkz/feathers that referenced this issue Jun 2, 2024
This commit adds the update method prototype to the MongoDBService class in index.ts. This allows the update method to be used with the correct typings. This is related to issue feathersjs#3485
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