Reputation: 1
I used the default FeathersJS generator to boilerplate an api and create a service.
I am trying to rewrite the create
method in the service. At defining the method I get the following TS error:
Property 'create' in type 'UserService<ServiceParams>' is not assignable to the same property in base type 'KnexService<{ email: string; password: string; id: string; }, { email: string; password: string; }, KnexAdapterParams<AdapterQuery>, Partial<{ email: string; password: string; }>>'.
Type '(data: { email: string; password: string; }, params?: KnexAdapterParams<AdapterQuery> | undefined) => Promise<{ email: string; password: string; id: string; }>' is not assignable to type '{ (data: { email: string; password: string; }, params?: KnexAdapterParams<AdapterQuery> | undefined): Promise<{ email: string; password: string; id: string; }>; (data: { ...; }[], params?: KnexAdapterParams<...> | undefined): Promise<...>; (data: { ...; } | { ...; }[], params?: KnexAdapterParams<...> | undefined): P...'.
Types of parameters 'data' and 'data' are incompatible.
Type '{ email: string; password: string; }[]' is missing the following properties from type '{ email: string; password: string; }': email, password ts(2416)
My types are defined with zod
:
import { z } from 'zod'
const createUserSchema = z.object({
email: z.string(),
password: z.string(),
})
const userSchema = createUserSchema.extend({
id: z.string(),
})
type User = z.infer<typeof userSchema>
type CreateUser = z.infer<typeof createUserSchema>
export { CreateUser, User, userSchema }
And my service looks like this:
import type { Params } from '@feathersjs/feathers'
import type { KnexAdapterOptions, KnexAdapterParams } from '@feathersjs/knex'
import { KnexService } from '@feathersjs/knex'
import { AdapterQuery } from '@feathersjs/adapter-commons'
import type { Application } from '../../declarations'
import { CreateUser, User } from '../../models/users.model'
type UserQuery = any
export type { UserQuery }
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,
CreateUser
> {
create(data: CreateUser, params?: KnexAdapterParams<AdapterQuery> | undefined): Promise<User> {
return super.create(data, params)
}
}
export const getOptions = (app: Application): KnexAdapterOptions => {
return {
paginate: app.get('paginate'),
Model: app.get('postgresqlClient'),
name: 'users'
}
}
In the IDE I see also the following error description:
Types of parameters data and data are incompatible. Type { email: string; password: string; }[] is missing the following properties from type { email: string; password: string; }: email, password
If I understand it correctly, the problem is, that data
is expected to be an array.
What causes the issue, and how can I resolve it?
What I tried:
Relevant packages:
Upvotes: 0
Views: 81