feathers-hooks-common icon indicating copy to clipboard operation
feathers-hooks-common copied to clipboard

Typescript: Hook type no longer compatible for disablePagination

Open lwhiteley opened this issue 5 years ago • 3 comments
trafficstars

Steps to reproduce

Using disablePagination hook produces a typescript error

eg. 1

// /src/app.hooks.ts
import { disablePagination } from "feathers-hooks-common";

export default {
  before: {
    all: [],
    find: [disablePagination()],
    get: [],
   ...
 Types of property 'find' are incompatible.
   Type 'Hook<any, Service<any>>[]' is not assignable to 
     type 'Hook<any, Service<any>> | Hook<any, Service<any>>[] | undefined'.

eg 2

// /src/app.hooks.ts
import { disablePagination } from "feathers-hooks-common";

export default {
  before: {
    all: [],
    find: disablePagination(),
    get: [],
   ...
Types of property 'find' are incompatible.
    Type 'Hook<any, Service<any>>' is not assignable to 
      type 'Hook<any, Service<any>> | Hook<any, Service<any>>[] | undefined'.

Actual behavior

Application does not compile when hook is used

Expected behavior

Application should compile without issues

Module versions :

"@feathersjs/feathers": "^4.5.0", "feathers-hooks-common": "^5.0.1", "tslint": "^5.20.1", "typescript": "^3.7.5"

If it helps.

im using yarn as the package manager

lwhiteley avatar Jan 19 '20 05:01 lwhiteley

Having the same issue with validateSchema

feathers-hooks-common: 5.0.3 @feathersjs/feathers: 4.5.1

Also using yarn

Conversion of type 'Hook<any, Service<any>>' to type 'Hook<AdvancedSearchResult, Service<AdvancedSearchResult>>' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Types of parameters 'hook' and 'hook' are incompatible.
    Type 'HookContext<AdvancedSearchResult, Service<AdvancedSearchResult>>' is not comparable to type 'HookContext<any, Service<any>>'.
      Types of property 'app' are incompatible.
        Type 'Application<{}>' is missing the following properties from type 'Application<{}>': lookup, channels, channel, publish, and 2 more.ts(2352)

As a workaround for now I'm doing the following:

{
    after: {
	all: [],
	find: [(validateSchema(responseSchema(), ajv) as unknown) as Hook],
	get: [],
	create: [],
	update: [],
	patch: [],
	remove: [],
    },
}

eXigentCoder avatar Jul 30 '20 07:07 eXigentCoder

@eXigentCoder it works! But hope for fixing.

holmesconan avatar Aug 13 '20 14:08 holmesconan

did you get the solution???

ishfaq-dar avatar Oct 19 '21 07:10 ishfaq-dar