feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
14.97k stars 742 forks source link

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

Open thomasarbona opened 1 month ago

thomasarbona commented 1 month ago

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"
  }