feathersjs / feathers

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

Documentation in TS #2321

Closed gmwill934 closed 3 years ago

gmwill934 commented 3 years ago

I'm following the TS tutorial https://docs.feathersjs.com/guides/basics/services.html#service-methods

import { Application, Id, NullableId, Params, Service } from '@feathersjs/feathers';

class MyService implements Service<any> {
  async find(params: Params) {}
  async get(id: Id, params: Params) {}
  async create(data: any, params: Params) {}
  async update(id: NullableId, data: any, params: Params) {}
  async patch(id: NullableId, data: any, params: Params) {}
  async remove(id: NullableId, params: Params) {}
}

app.use('/my-service', new MyService());

I'm getting an error when declaring the create method which shows

Property 'create' in type 'Users' is not assignable to the same property in base type 'ServiceOverloads<any> & ServiceAddons<any> & ServiceMethods<any>'.
  Type '(data: any, params: any) => Promise<void>' is not assignable to type '{ (data: Partial<any>, params?: Params | undefined): Promise<any>; (data: Partial<any>[], params?: Params | undefined): Promise<any[]>; } & ((data: Partial<...> | Partial<...>[], params?: Params | undefined) => Promise<...>)'.
    Type '(data: any, params: any) => Promise<void>' is not assignable to type '{ (data: Partial<any>, params?: Params | undefined): Promise<any>; (data: Partial<any>[], params?: Params | undefined): Promise<any[]>; }'.
      Type 'Promise<void>' is not assignable to type 'Promise<any[]>'.
        Type 'void' is not assignable to type 'any[]'

Can someone please show me the way to fix this?

bertho-zero commented 3 years ago

You probably need to return a value.