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

Missing "fetchOptions" type declaration on find method in useStrapi composable #415

Open
Sparo opened this issue May 29, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Sparo
Copy link

Sparo commented May 29, 2024

Version

@nuxtjs/strapi: v1.12.0
nuxt: v3.11.2

Steps to reproduce

I am using find method per docs: https://strapi.nuxtjs.org/usage#find
Here we have documented 3 arguments where 3rd is fetchOptions (https://github.com/unjs/ofetch/blob/main/src/types.ts#L34)
based on that - I want to pass query object into fetchOptions so I can do some customization on the Strapi V4 side. Here is the code:

const { find } = useStrapi()

const response = await find<BlogItem>('articles', { filters: { slug } }, {
    query: {
        customQueryParam: 'something'
    }
 })

Everything is working fine but typescript is reporting following error: Error: Expected 1-2 arguments, but got 3 .ts(2554)

What is Expected?

I expect typescript linter not to report invalid number of arguments.

What is actually happening?

What I have checked is that in the source code on line: https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/composables-v4/useStrapi.ts#L5 are defined just two arguments find<F = T>(contentType: string, params?: Strapi4RequestParams): Promise<Strapi4ResponseMany<F>> but in the actual code of the find method there are 3 of them: https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/composables-v4/useStrapi4.ts#L22

I assume that on the line https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/composables-v4/useStrapi.ts#L5 is missing type declaration something like this:

import type { FetchOptions } from 'ofetch';

// ...

find: <T>(contentType: string, params?: Strapi4RequestParams, fetchOptions?: FetchOptions) => Promise<T>;

I guess typescript issue would be fixed if I would use const { find } = useStrapi4() but since Strapi v4 is the default I assume that useStrapi() should follow useStrapi4() type structure by default.

all the best,
Nenad

@Sparo Sparo added the bug Something isn't working label May 29, 2024
@Sparo Sparo changed the title Missing "fetchOptions" type declaration on find method on useStrapi composable Missing "fetchOptions" type declaration on find method in useStrapi composable May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant