-
-
Notifications
You must be signed in to change notification settings - Fork 763
Closed
Labels
Description
Environment
Nitro: 2.12.7
Node: v20.12.1
export default defineNitroConfig({
srcDir: "server",
compatibilityDate: "2025-10-21",
imports: {
imports: [
{
name: "foo",
from: resolve(import.meta.dirname, "./pkg/src/index.js"),
typeFrom: resolve(import.meta.dirname, "./pkg/dts/index.d.ts"),
},
],
},
});Reproduction
- Run
pnpm prepare. - Inspect
.nitro/types/nitro-imports.d.ts. - Look for a
fooconst; its type isstring, but should bestring | number | boolean(seepkg/dts/index.d.ts).
Describe the bug
Nitro does not use the typeFrom option of registered autoimports to generate declaration files, which may cause type declarations to not be found.
Nitro uses unimport's generateTypeDeclarations to generate declaration files' content, which supports the typeFrom option. However, a custom resolver that is missing typeFrom support is provided.
Additional context
- Nuxt had the same issue for app autoimports: fix(nuxt): support autoimports'
typeFromproperty when generating type templates nuxt/nuxt#33373. - Generated exports with
toExportsshould likewise usetypeFromif provided, buttoExportsdoes not currently supporttypeFrom. I submitted a PR to address this too.