Skip to content

Commit 85e6a99

Browse files
chore: wip
1 parent be2bd7a commit 85e6a99

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

packages/dtsx/test/dts.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ describe('dts-generation', () => {
3939
'module',
4040
'namespace',
4141
'type',
42+
'type-interface-imports',
4243
'variable',
4344
]
4445

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Regression test for type/interface imports in d.ts files
2+
// When a type or interface uses an imported type, the import should be included in the d.ts file
3+
4+
import type { ParsedPath } from 'node:path'
5+
import { readFileSync } from 'node:fs'
6+
7+
/**
8+
* Internal type that uses an imported type
9+
*/
10+
type FileInfo = {
11+
path: ParsedPath
12+
content: string
13+
}
14+
15+
/**
16+
* Interface that uses an imported type
17+
*/
18+
interface FileMetadata {
19+
parsedPath: ParsedPath
20+
size: number
21+
}
22+
23+
/**
24+
* Exported interface that uses another interface
25+
*/
26+
export interface FileDetails extends FileMetadata {
27+
name: string
28+
}
29+
30+
/**
31+
* Exported function that returns a type using imported types
32+
*/
33+
export function getFileInfo(filePath: string): FileInfo {
34+
return {
35+
path: {} as ParsedPath,
36+
content: readFileSync(filePath, 'utf-8')
37+
}
38+
}
39+
40+
/**
41+
* Exported function that uses interface parameter
42+
*/
43+
export function processFile(metadata: FileMetadata): void {
44+
console.log(metadata)
45+
}
46+
47+
/**
48+
* Exported type alias that uses imported type
49+
*/
50+
export type PathInfo = ParsedPath & {
51+
exists: boolean
52+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import type { ParsedPath } from 'node:path';
2+
/**
3+
* Exported function that returns a type using imported types
4+
*/
5+
export declare function getFileInfo(filePath: string): FileInfo;
6+
/**
7+
* Exported function that uses interface parameter
8+
*/
9+
export declare function processFile(metadata: FileMetadata): void;
10+
/**
11+
* Interface that uses an imported type
12+
*/
13+
declare interface FileMetadata {
14+
parsedPath: ParsedPath
15+
size: number
16+
}
17+
/**
18+
* Exported interface that uses another interface
19+
*/
20+
export declare interface FileDetails extends FileMetadata {
21+
name: string
22+
}
23+
/**
24+
* Internal type that uses an imported type
25+
*/
26+
declare type FileInfo = {
27+
path: ParsedPath
28+
content: string
29+
}
30+
/**
31+
* Exported type alias that uses imported type
32+
*/
33+
export type PathInfo = ParsedPath & {
34+
exists: boolean
35+
}

0 commit comments

Comments
 (0)