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

Errors when building with TypeScript - No overload matches this call #167

Open
peterbrinck opened this issue Feb 19, 2024 · 2 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@peterbrinck
Copy link

Hi! 👋

I kept getting some errors (No overload matches this call. / Type 'ObjectPlugin<any[]>' is not assignable to type 'Plugin') when building my application with TypeScript

It seems that Vue excepts the plugin to be the type ObjectPlugin but i18nVue is type Plugin
I'm not that strong in TypeScript, so I don't have a clear idea if it's on purpose or anything, but I managed to fix it by casting the plugin as an ObjectPlugin

My fix:

.use(<ObjectPlugin>i18nVue, {
  resolve: async (lang: string) => {
    const langs = import.meta.glob('../../lang/*.json');
    return <Promise<LanguageJsonFileInterface>>await langs[`../../lang/${lang}.json`]()
  }
})

Error output from the build command:

bun run build
$ vue-tsc && vite build
resources/js/app.ts:39:12 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(plugin: Plugin<[{ resolve: (lang: string) => Promise<unknown>; }]>, options_0: { resolve: (lang: string) => Promise<unknown>; }): App<Element>', gave the following error.
    Argument of type 'Plugin' is not assignable to parameter of type 'Plugin<[{ resolve: (lang: string) => Promise<unknown>; }]>'.
      Type 'ObjectPlugin<any[]>' is not assignable to type 'Plugin<[{ resolve: (lang: string) => Promise<unknown>; }]>'.
        Type 'ObjectPlugin<any[]>' is not assignable to type 'FunctionPlugin<[{ resolve: (lang: string) => Promise<unknown>; }]>'.
          Type 'ObjectPlugin<any[]>' is not assignable to type '(app: App<any>, options_0: { resolve: (lang: string) => Promise<unknown>; }) => any'.
            Type 'ObjectPlugin<any[]>' provides no match for the signature '(app: App<any>, options_0: { resolve: (lang: string) => Promise<unknown>; }): any'.
  Overload 2 of 2, '(plugin: Plugin<{ resolve: (lang: string) => Promise<unknown>; }>, options: { resolve: (lang: string) => Promise<unknown>; }): App<Element>', gave the following error.
    Argument of type 'Plugin' is not assignable to parameter of type 'Plugin<{ resolve: (lang: string) => Promise<unknown>; }>'.
      Type 'ObjectPlugin<any[]>' is not assignable to type 'Plugin<{ resolve: (lang: string) => Promise<unknown>; }>'.
        Type 'ObjectPlugin<any[]>' is not assignable to type 'FunctionPlugin<{ resolve: (lang: string) => Promise<unknown>; }>'.
          Type 'ObjectPlugin<any[]>' is not assignable to type '(app: App<any>, options: { resolve: (lang: string) => Promise<unknown>; }) => any'.
            Type 'ObjectPlugin<any[]>' provides no match for the signature '(app: App<any>, options: { resolve: (lang: string) => Promise<unknown>; }): any'.

39       .use(i18nVue, {
              ~~~~~~~

Found 1 error in resources/js/app.ts:39
@xiCO2k
Copy link
Owner

xiCO2k commented Feb 19, 2024

Thanks for this one, if anyone wants to make a PR for this one I appreciate it!

@xiCO2k xiCO2k added enhancement New feature or request good first issue Good for newcomers labels Feb 19, 2024
@yangfancn
Copy link

yangfancn commented Jul 5, 2024

My fix:

import { i18nVue } from "laravel-vue-i18n"

...
.use(i18nVue as any, {
        resolve: async (lang: string) => {
          const langFiles = import.meta.glob('../../../lang/*.json');
          return await langFiles[`../../../lang/${lang}.json`]()
        }
      })
.mount(el)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants