Skip to content

When a file only contains global declarations, it is not auto-imported #448

@Anoesj

Description

@Anoesj

Environment

unimport: 5.0.0
node: 22.14

Reproduction

https://stackblitz.com/edit/github-av9ljigg?file=.nuxt%2Ftypes%2Fimports.d.ts

After the project is installed and the dev server has started, go to file .nuxt/types/imports.d.ts.

Describe the bug

When a file only contains declare global, but does not contain any type exports or regular exports, the file is skipped during auto-import. As soon as a regular or type export is added to that file, it is auto-imported and the global declaration becomes available in the type layer of the app.

Repro explanation

In the repro, which is a basic Nuxt project setup, I manually auto-import the following three files:

1. a.ts

export const a = 'a';
export type A = typeof a;

2. b.ts

export const b = 'b';

declare global {
  type B = typeof b;
}

3. c.ts

export {};

declare global {
  type C = 'C';
}

This has the following effect on .nuxt/types/imports.d.ts (irrelevant stuff is left out):

// Generated by auto imports
export {}
declare global {
  const a: typeof import('../../extra/a')['a']
  const b: typeof import('../../extra/b')['b']
}

// for type re-export
declare global {
  // @ts-ignore
  export type { A } from '../../extra/a'
  import('../../extra/a')
}

import { UnwrapRef } from 'vue'
declare module 'vue' {
  interface ComponentCustomProperties {
    readonly a: UnwrapRef<typeof import('../../extra/a')['a']>
    readonly b: UnwrapRef<typeof import('../../extra/b')['b']>
  }
}

As you can see, c.ts is entirely ignored, while global declarations of b.ts are included, because it contains a regular export.

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions