Type error TS2322(`resolvePageComponent` + `vite`'s `import.meta.glob`)
See original GitHub issue- Laravel Vite Plugin Version: 0.6.1
- Laravel Version: 9.39.0
- Node Version: 16.17.0
- NPM Version: 8.19.1
- Host operating system: Ubuntu22.04(Laravel Sail 8.1) on Docker on Ubuntu20.04(WSL2)
- Web Browser & Version: no relation
- Running in Sail / Docker: Sail
Description:
I consulted on Discord about an issue #161 I created earlier, and got a reply saying it might be a bug, so I created this new one.
I think the cause of the error is that the type of the second arg of resolvePageComponent
of laravel-vite-plugin
and the return type of import.meta.glob
of vite
do not match.
Because if I use import.meta.globEager
instead of import.meta.glob
I get no error. (Unfortunately using import.meta.globEager
causes no code-splitting for the pages, so this is not a workaround)
Currently I avoid type errors by calling resolvePageComponent
on the javascript file, but hopefully the laravel-vite-plugin
will fix it.
Thank you.
// laravel-vite-plugin/inertia-helpers/index.d.ts
export declare function resolvePageComponent<T>(path: string, pages: Record<string, Promise<T> | (() => Promise<T>)>): Promise<T>;
// vite/types/importGlob.d.ts
// https://github.com/vitejs/vite/blob/v3.2.4/packages/vite/types/importGlob.d.ts#L39
・・・
export interface ImportGlobFunction {
/**
* Import a list of files with a glob pattern.
*
* Overload 1: No generic provided, infer the type from `eager` and `as`
*/
<
Eager extends boolean,
As extends string,
T = As extends keyof KnownAsTypeMap ? KnownAsTypeMap[As] : unknown
>(
glob: string | string[],
options?: ImportGlobOptions<Eager, As>
): (Eager extends true ? true : false) extends true
? Record<string, T>
: Record<string, () => Promise<T>>
/**
* Import a list of files with a glob pattern.
*
* Overload 2: Module generic provided, infer the type from `eager: false`
*/
<M>(
glob: string | string[],
options?: ImportGlobOptions<false, string>
): Record<string, () => Promise<M>>
/**
* Import a list of files with a glob pattern.
*
* Overload 3: Module generic provided, infer the type from `eager: true`
*/
<M>(
glob: string | string[],
options: ImportGlobOptions<true, string>
): Record<string, M>
}
・・・
Steps To Reproduce:
See #161.
Issue Analytics
- State:
- Created 10 months ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
[v3] Document type inference with import.meta.glob #9599
Describe the bug When using import.meta.glob with vite v3, no generic type ... src/main.ts:4:15 - error TS2571: Object is of type 'unknown'.
Read more >Vite — Resolve `import.meta.glob` in TypeScript - Future Studio
glob function allowing you to resolve files from a path. In combination with TypeScript, you may have issues that it doesn't pick up...
Read more >Default Persistent Layout In Laravel + Inertia + Vite
meta.glob as a second argument to instruct Vite which files to bundle. Problem here is the import gets returned from this resolvePageComponent ......
Read more >Using Vite with Inertia — Laravel, Vue & Tailwind
You need to specify file extensions when importing Vue components, like import FormInput from "@/Shared/Form/FormInput.vue". "app.js" is the ...
Read more >Vite in production - Laracasts
The official docs says to use. Copy Code resolve: (name) => resolvePageComponent(./Pages/${name}.vue, import.meta.glob('./Pages/**/*.vue', {eager: true})),.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Worked perfect!!!. Thanks so much.
Laravel does not officially support Typescript, so we won’t document that.
If you feel there is an improvement to be made, we would welcome a PR to improve the types.