marshallswain / feathers-pinia

Connect your Feathers API to the elegant data store for Vue
52 stars 22 forks source link

Typing doesn't work very well for services #144

Closed Granipouss closed 8 months ago

Granipouss commented 10 months ago

Hey,

I am trying to use feather-pinia v4 with feathersjs v5. But it seems that typescript is struggling to infer types for the services.

export const api = createPiniaClient(client, {
  pinia: getActivePinia(),
  idField: '_id'
})

const mediaStore = api.service('medias')
const media = mediaStore.get('id')

I get media resolved as any.

I think that's because typescript cannot infer type in PiniaService. I beleive that can be solved by explicitly annoting return types for the functions.

export class PiniaService<Svc extends FeathersService> {
  // [...]

  /**
   * retrieve a record from the API server by id. The record is reactive.
   */
  async get(id: Id, _params?: MaybeRef<Params<Query>>): ReturnType<Svc['get']> {
    const params = getParams(_params)
    const result = await this.service.get(id, params)
    return result
  }
}

Cheers

marshallswain commented 8 months ago

I've merged the PR. Please open another issue (or reopen if applicable) if you find more work is needed. Thanks for the PR.