Skip to content

import.meta.glob() return type should be Partial #20137

Open
@hyunbinseo

Description

@hyunbinseo

Describe the bug

Current Behavior

// Type: Record<string, () => Promise<unknown>>
const modules = import.meta.glob('*.ts');

// This doesn't trigger TypeScript errors, but can cause runtime issues
const loader = modules['nonexistent-file.ts']; // Type: () => Promise<unknown>
await loader(); // Runtime error: loader is undefined

Expected Behavior

// Type: Partial<Record<string, () => Promise<unknown>>>
const modules = import.meta.glob('*.ts');

// TypeScript should enforce safe access
// Type: (() => Promise<unknown>) | undefined
const loader = modules['nonexistent-file.ts'];
const safeLoader = modules?.['some-file.ts'];

Reproduction

Steps to reproduce

No response

System Info

System:
  OS: Windows 11 10.0.26100
  CPU: (8) x64 Intel(R) Core(TM) Ultra 7 258V
  Memory: 4.38 GB / 31.51 GB
Binaries:
  Node: 24.1.0 - ~\AppData\Local\fnm_multishells\32740_1748604076193\node.EXE
  npm: 11.3.0 - ~\AppData\Local\fnm_multishells\32740_1748604076193\npm.CMD
  pnpm: 10.11.0 - ~\AppData\Local\fnm_multishells\32740_1748604076193\pnpm.CMD
Browsers:
  Edge: Chromium (131.0.2903.112)
npmPackages:
  vite: ^6.3.5 => 6.3.5

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions