#3079·feathers

Typescript inference of service params

Author: gorangoCreated Feb 26, 2023Updated Sep 9, 2025

Steps to reproduce

In a fresh copy of feathers-chat, paste the following snippet at the end of the app.ts file:

typescript
(async () => {
  const query: any = {
    text: 'foo'
  }
  const messages = await app.service('messages').find({
    query,
    paginate: false
  })
  messages.forEach(() => {})
})

Expected behavior

There should be no Typescript errors.

Actual behavior

Property 'forEach' does not exist on type 'Paginated<{ id: number; user: { password?: string | undefined; githubId?: number | undefined; avatar?: string | undefined; id: number; email: string; }; text: string; createdAt: number; userId: number; }>'.

Workaround

Using explicit type assertion on query props resolves the errors:

typescript
(async () => {
  const query: any = {
    text: 'foo'
  }
  const messages = await app.service('messages').find({
    query: {
      text: query.text as string
    },
    paginate: false
  })
  messages.forEach(() => {})
})

Possibly related to https://github.com/feathersjs/feathers/issues/3012 as I think both issues suffer from the way HookContext interprets the current Service<Params>.

Discord thread

System configuration

Module versions: v5

NodeJS version: 16,18

Operating System: linux

Browser Version: -

React Native Version: -

Module Loader: es6