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

[v3] Document type inference with import.meta.glob #9599

Closed
7 tasks done
aboutsimon opened this issue Aug 9, 2022 · 1 comment · Fixed by #9709
Closed
7 tasks done

[v3] Document type inference with import.meta.glob #9599

aboutsimon opened this issue Aug 9, 2022 · 1 comment · Fixed by #9709
Labels
documentation Improvements or additions to documentation

Comments

@aboutsimon
Copy link

aboutsimon commented Aug 9, 2022

Describe the bug

When using import.meta.glob with vite v3, no generic type is provided anymore. The JS Doc provides you with this information, but it would have helped me to have it in the official docs easily available.

Also, is this not a breaking change for typescript users, strictly speaking?

Thanks for a great project.

Reproduction

https://stackblitz.com/edit/vitejs-vite-lgkx3h?file=src/main.ts&view=editor

System Info

System:
    OS: Linux 5.18 Arch Linux
    Memory: 12.14 GB / 23.23 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node
    Yarn: 1.22.15 - ~/.nvm/versions/node/v16.15.1/bin/yarn
    npm: 8.11.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
  Browsers:
    Chromium: 104.0.5112.79
    Firefox: 103.0.1
  npmPackages:
    vite: ^3.0.4 => 3.0.4

Used Package Manager

yarn

Logs

src/main.ts:4:15 - error TS2571: Object is of type 'unknown'.

4 const error = (await moduleImports[0]()).default;

Validations

@sapphi-red
Copy link
Member

no generic type is provided anymore.

I think it is partially still there. (the syntax has changed though)

import.meta.glob<Record<string, string>>('./*.txt') // v2
import.meta.glob<string>('./*.txt') // v3

/**
* 2. Module generic provided, infer the type from `eager: false`
*/
<M>(
glob: string | string[],
options?: ImportGlobOptions<false, string>
): Record<string, () => Promise<M>>
/**
* 3. Module generic provided, infer the type from `eager: true`
*/
<M>(
glob: string | string[],
options: ImportGlobOptions<true, string>
): Record<string, M>

@sapphi-red sapphi-red added documentation Improvements or additions to documentation and removed pending triage labels Aug 9, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Aug 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants