feathersjs-ecosystem / feathers-authentication-management

Adds sign up verification, forgotten password reset, and other capabilities to local feathers-authentication
https://feathers-a-m.netlify.app/
MIT License
246 stars 98 forks source link

[dove] TypeScript issue when using hook addVerification #195

Closed mdartic closed 1 year ago

mdartic commented 1 year ago

Steps to reproduce

These last 2 items usually allow us to regen enough of your app to recreate the issue. We may otherwise ask you to provide a minimal GitHub repo or gist isolating the issue.

Expected behavior

Tell us what should happen

This should work, and don't break the compilation ?

Actual behavior

Tell us what happens instead

TS compilation breaks.

/home/mdartic/workspace/lck/r & d/feathers-dove-fam/node_modules/ts-node/src/index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/services/users/users.service.ts:22:30 - error TS2345: Argument of type '{ around: { all: never[]; get: (((context: HookContext<Application<any, any>, any>, _next?: NextFunction | undefined) => Promise<any>) | ((this: any, context: HookContext<...>, next?: AsyncMiddleware<...> | undefined) => Promise<...>))[]; ... 4 more ...; remove: (((context: HookContext<Application<any, any>, any>, _...' is not assignable to parameter of type 'HookOptions<Application, UsersService>'.
  Type '{ around: { all: never[]; get: (((context: HookContext<Application<any, any>, any>, _next?: NextFunction | undefined) => Promise<any>) | ((this: any, context: HookContext<...>, next?: AsyncMiddleware<...> | undefined) => Promise<...>))[]; ... 4 more ...; remove: (((context: HookContext<Application<any, any>, any>, _...' is not assignable to type 'HookMap<Application, UsersService>'.
    Types of property 'before' are incompatible.
      Type '{ create: ((context: HookContext<any, Service<any>>) => Promise<HookContext<any, Service<any>>>)[]; }' is not assignable to type 'HookTypeMap<Application, UsersService> | undefined'.
        Type '{ create: ((context: HookContext<any, Service<any>>) => Promise<HookContext<any, Service<any>>>)[]; }' is not assignable to type 'HookMethodMap<Application, UsersService>'.
          Type '{ create: ((context: HookContext<any, Service<any>>) => Promise<HookContext<any, Service<any>>>)[]; }' is not assignable to type '{ find?: SelfOrArray<HookFunction<Application, UsersService>> | undefined; get?: SelfOrArray<HookFunction<Application, UsersService>> | undefined; ... 31 more ...; _remove?: SelfOrArray<...> | undefined; }'.
            Types of property 'create' are incompatible.
              Type '((context: HookContext<any, Service<any>>) => Promise<HookContext<any, Service<any>>>)[]' is not assignable to type 'SelfOrArray<HookFunction<Application, UsersService>> | undefined'.
                Type '((context: HookContext<any, Service<any>>) => Promise<HookContext<any, Service<any>>>)[]' is not assignable to type 'HookFunction<Application, UsersService>[]'.
                  Type '(context: HookContext<any, Service<any>>) => Promise<HookContext<any, Service<any>>>' is not assignable to type 'HookFunction<Application, UsersService>'.
                    Types of parameters 'context' and 'context' are incompatible.
                      Type 'HookContext<Application, UsersService>' is not assignable to type 'HookContext<any, Service<any>>'.
                        Types of property 'app' are incompatible.
                          Type 'Omit<import("/home/mdartic/workspace/lck/r & d/feathers-dove-fam/node_modules/@types/koa/index.d.ts")<DefaultState, DefaultContext>, "listen"> & Application<...> & ApplicationAddons' is missing the following properties from type 'Application<{}>': methods, disable, disabled, enable, and 5 more.

22   app.service('users').hooks(usersHooks)
                                ~~~~~~~~~~

    at createTSError (/home/mdartic/workspace/lck/r & d/feathers-dove-fam/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/home/mdartic/workspace/lck/r & d/feathers-dove-fam/node_modules/ts-node/src/index.ts:863:19)
    at getOutput (/home/mdartic/workspace/lck/r & d/feathers-dove-fam/node_modules/ts-node/src/index.ts:1077:36)
    at Object.compile (/home/mdartic/workspace/lck/r & d/feathers-dove-fam/node_modules/ts-node/src/index.ts:1433:41)
    at Module.m._compile (/home/mdartic/workspace/lck/r & d/feathers-dove-fam/node_modules/ts-node/src/index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
    at Object.require.extensions.<computed> [as .ts] (/home/mdartic/workspace/lck/r & d/feathers-dove-fam/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:998:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1022:19) {
  diagnosticCodes: [ 2345 ]
}
[nodemon] app crashed - waiting for file changes before starting...

System configuration

Tell us about the applicable parts of your setup.

A github repo is available https://github.com/mdartic/feathers-dove-fam

Module versions (especially the part that's not working):

NodeJS version: 18

Operating System: Linux Mint

Other ideas

I don't know why there are these errors. feathers-hooks-commons seems to be in the same case. Maybe I'm wrong when installing / using those packages, don't really know, but hard to find the good path.

I try to override the dependencies of fam, you can check the override branch. https://github.com/mdartic/feathers-dove-fam/commit/2145bce5dffc473af426716331ba580cfcff574a

But this doesn't help. (maybe related to feathers-hooks-common, didn't make the test with only fam.)

Do you have an idea ?

mdartic commented 1 year ago

I've updated feathers-hooks-common package to its pre-release, errors for this package disappear. I try to update overrides for the fam package, even feathers-hooks-common that is used, but I feel like a bad tester, trying to find a path without knowing exactly what I'm doing...

fratzinger commented 1 year ago

Closed by #196. Released as feathers-authentication-management@5.0.0-pre.0 🎉