ITADN

Auto-imported namespaces broken

#473OpenAnoesj 创建于 2025-10-02
bug
A
Anoesjcommented
### Environment * ### Reproduction https://github.com/Anoesj/unimport-namespaces ### Describe the bug With the current way `unimport` declares exports of auto-imports in the `.d.ts` file, problems like the following one happen a lot with namespaces (are ESM module exports considered namespaces too?): **globally-shared/validation/zod.ts:** ```ts export * as z from 'zod'; ``` **The generated `.d.ts` file:** ```ts declare global { const z: typeof import('../../../../globally-shared/validation/zod')['z'] } ``` **Some `.ts` file that uses the auto-imports:** ```ts type ZodIssue = z.core.$ZodIssue; // ^ Cannot find namespace 'z'. type ZodIssuePlease = typeof z.core.$ZodIssue; // ^ Property '$ZodIssue' does not exist on type 'typeof import(...)'. /* NOTE: The only workaround that works for the issue above is to add `export type $ZodIssue = z.core.$ZodIssue;` in `globally-shared/validation/zod.ts`. That's bad DX though, especially if `z.core.$ZodIssue` would have had generics that you'd need to redefine! */ const aString: z.ZodType = z.string(); // ^ Cannot find namespace 'z'. const aStringWorkaround: InstanceType<typeof z.ZodType> = z.string(); // Works as a workaround, but this sucks... ``` When you (manually) change the notation in the `.d.ts` file unimport generates to... ```ts declare global { export { z } from '../../../../globally-shared/validation/zod' } ``` ...everything works perfectly without any need for workarounds. ### Additional context _No response_ ### Logs ```sh ```
0 条评论