-
Notifications
You must be signed in to change notification settings - Fork 76
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Reproduction
A Nuxt repro, where unimport is used under the hood by unplugin-auto-import: https://github.com/Anoesj/unimport-namespaces
As described in the repo's README:
pnpm i && pnpm dev- See lots of errors in
app.vue - Manually edit
.nuxt/types/imports.d.ts:
// Replace this line:
const z: typeof import('../../app/utils/zod')['z']
// With this line:
export { z } from '../../app/utils/zod'- See errors go away (except the one at
typeof z.core.$ZodIssuewhich is expected)
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:
export * as z from 'zod';The generated .d.ts file:
declare global {
const z: typeof import('../../../../globally-shared/validation/zod')['z']
}Some .ts file that uses the auto-imports:
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...
declare global {
export { z } from '../../../../globally-shared/validation/zod'
}...everything works perfectly without any need for workarounds.
Additional context
No response
Logs
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working