Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dove: KnexService customization - Typescript error #2918

Closed
rmtngh opened this issue Dec 11, 2022 · 3 comments · Fixed by #2939
Closed

dove: KnexService customization - Typescript error #2918

rmtngh opened this issue Dec 11, 2022 · 3 comments · Fixed by #2939

Comments

@rmtngh
Copy link

rmtngh commented Dec 11, 2022

Steps to reproduce

1- Generate an app using npm create feathers@pre feathers-chat with:
Typescript, KoaJS, HTTP & Real time, yarn, TypeBox, PostgreSQL

2- Add a custom implementation to Users service (doc: https://dove.feathersjs.com/guides/cli/service.class.html#service-customization)

Example:

import type { Params } from '@feathersjs/feathers'
import { KnexService } from '@feathersjs/knex'
import type { KnexAdapterParams, KnexAdapterOptions } from '@feathersjs/knex'

import type { Application } from '../../declarations'
import type { User, UserData, UserQuery } from './users.schema'

export interface UserParams extends KnexAdapterParams<UserQuery> {}

// By default calls the standard Knex adapter service methods but can be customized with your own functionality.
export class UserService<ServiceParams extends Params = UserParams> extends KnexService<
  User,
  UserData,
  ServiceParams
> {
  find(params: ServiceParams) {
    return super.find(params)
  }
  create(data: UserData, params: ServiceParams){
    return super.create(data, params)
  }
}

export const getOptions = (app: Application): KnexAdapterOptions => {
  return {
    paginate: app.get('paginate'),
    Model: app.get('postgresqlClient'),
    name: 'users'
  }
}

Expected behavior

Custom find and create methods should override KnexService's methods with no errors.

Actual behavior

Typescript error:

Property 'create' in type 'UserService<ServiceParams>' is not assignable to the same property in base type 'KnexService<{ password?: string | undefined; googleId?: string | undefined; auth0Id?: string | undefined; id: number; email: string; }, { password?: string | undefined; googleId?: string | undefined; auth0Id?: string | undefined; email: string; }, ServiceParams>'

System configuration

Tell us about the applicable parts of your setup.

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

NodeJS version: v16.18.1

Operating System: MacOS 11.5

Browser Version: N/A

React Native Version: N/A

Module Loader:

@daffl
Copy link
Member

daffl commented Dec 18, 2022

You are correct, that did not work. The page at https://dove.feathersjs.com/guides/cli/service.class.html has been updated now with more complete examples that should work as expected. Note that the docs are for .pre.34 which has a patch schema now.

@rmtngh
Copy link
Author

rmtngh commented Dec 19, 2022

Hi @daffl
Thanks a lot for the fix and your reply,
I tried generating a Message service with the latest version and pasted the create methods from the doc:

image

There is another ts error:

error TS2769: No overload matches this call.
  Overload 1 of 2, '(data: { text: string; }, params?: MessageParams | undefined): Promise<{ id: number; text: string; }>', gave the following error.
    Argument of type '{ text: string; } | { text: string; }[]' is not assignable to parameter of type '{ text: string; }'.
      Property 'text' is missing in type '{ text: string; }[]' but required in type '{ text: string; }'.
  Overload 2 of 2, '(data: { text: string; }[], params?: MessageParams | undefined): Promise<{ id: number; text: string; }[]>', gave the following error.
    Argument of type '{ text: string; } | { text: string; }[]' is not assignable to parameter of type '{ text: string; }[]'.
      Type '{ text: string; }' is missing the following properties from type '{ text: string; }[]': length, pop, push, concat, and 29 more.

22     return super.create(data, params)

Here are the dependencies:
image

@daffl
Copy link
Member

daffl commented Dec 20, 2022

Urgh, it turns out that those signatures weren't exported. This will be fixed via #2943 but for now it'll probably have to be async create(data: any in the implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants