diff --git a/playground/composables/index.ts b/playground/composables/index.ts index 6c8a0796..95cc1742 100644 --- a/playground/composables/index.ts +++ b/playground/composables/index.ts @@ -23,3 +23,5 @@ export type CustomType1 = string | number export interface CustomInterface1 { name: string } + +export enum CustomEnum {} diff --git a/src/node/scan-dirs.ts b/src/node/scan-dirs.ts index 043b1230..3a681122 100644 --- a/src/node/scan-dirs.ts +++ b/src/node/scan-dirs.ts @@ -61,6 +61,10 @@ export function dedupeDtsExports(exports: Import[]) { if (!i.type) return true + // import enum as both value and type + if (i.declaration === 'enum') + return true + return !exports.find(e => e.as === i.as && e.name === i.name && !e.type) }) } @@ -95,8 +99,11 @@ export async function scanExports(filepath: string, includeTypes: boolean, seen imports.push({ name, as: name, from: filepath, ...additional }) } else if (exp.type === 'declaration') { - if (exp.name) + if (exp.name) { imports.push({ name: exp.name, as: exp.name, from: filepath, ...additional }) + if (exp.declaration === 'enum') + imports.push({ name: exp.name, as: exp.name, from: filepath, type: true, declaration: exp.declaration, ...additional }) + } } else if (exp.type === 'star' && exp.specifier) { if (exp.name) { diff --git a/src/types.ts b/src/types.ts index b00307ff..f3ebf572 100644 --- a/src/types.ts +++ b/src/types.ts @@ -16,6 +16,8 @@ export interface ImportCommon { disabled?: boolean /** Won't output import in declaration file if true */ dtsDisabled?: boolean + /** Import declaration like const / var / enum */ + declaration?: string /** * Metadata of the import */ diff --git a/test/dts.test.ts b/test/dts.test.ts index f6d50e42..dde0f452 100644 --- a/test/dts.test.ts +++ b/test/dts.test.ts @@ -62,6 +62,7 @@ it('dts', async () => { "export {} declare global { const $: typeof import('jquery')['$'] + const CustomEnum: typeof import('/playground/composables/index')['CustomEnum'] const PascalCased: typeof import('/playground/composables/PascalCased')['PascalCased'] const THREE: typeof import('three') const bar: typeof import('/playground/composables/nested/bar/index')['bar'] diff --git a/test/scan-dirs.test.ts b/test/scan-dirs.test.ts index 67eec327..43648dfd 100644 --- a/test/scan-dirs.test.ts +++ b/test/scan-dirs.test.ts @@ -19,6 +19,18 @@ describe('scan-dirs', () => { "from": "index.ts", "name": "bump", }, + { + "as": "CustomEnum", + "from": "index.ts", + "name": "CustomEnum", + }, + { + "as": "CustomEnum", + "declaration": "enum", + "from": "index.ts", + "name": "CustomEnum", + "type": true, + }, { "as": "CustomInterface1", "from": "index.ts",