Skip to content

Commit 9378e1a

Browse files
committed
fix: improve InstanceType from dts
1 parent a0c5649 commit 9378e1a

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

src/core/declaration.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,7 @@ export function getDeclaration(ctx: Context, filepath: string, originalImports?:
114114
directive: stringifyDeclarationImports({ ...originalImports?.directive, ...imports.directive }),
115115
}
116116

117-
const head = ctx.options.version === 2.7
118-
? `export {}
119-
120-
declare module 'vue' {`
121-
: `export {}
117+
const head = `export {}
122118
123119
declare module 'vue' {`
124120

@@ -142,6 +138,11 @@ ${head}`
142138
}`
143139
}
144140
code += '\n}\n'
141+
code += `declare global {
142+
type GlobalInstanceType = {
143+
[Property in keyof GlobalComponents]: InstanceType<GlobalComponents[Property]>
144+
}
145+
}`
145146
return code
146147
}
147148

test/__snapshots__/dts.test.ts.snap

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ declare module 'vue' {
1515
TestComp: typeof import('test/component/TestComp')['default']
1616
}
1717
}
18-
"
18+
declare global {
19+
type GlobalInstanceType = {
20+
[Property in keyof GlobalComponents]: InstanceType<GlobalComponents[Property]>
21+
}
22+
}"
1923
`;
2024

2125
exports[`dts > directive only 1`] = `
@@ -31,7 +35,11 @@ declare module 'vue' {
3135
vLoading: typeof import('test/directive/Loading')['default']
3236
}
3337
}
34-
"
38+
declare global {
39+
type GlobalInstanceType = {
40+
[Property in keyof GlobalComponents]: InstanceType<GlobalComponents[Property]>
41+
}
42+
}"
3543
`;
3644

3745
exports[`dts > getDeclaration 1`] = `
@@ -52,7 +60,11 @@ declare module 'vue' {
5260
vLoading: typeof import('test/directive/Loading')['default']
5361
}
5462
}
55-
"
63+
declare global {
64+
type GlobalInstanceType = {
65+
[Property in keyof GlobalComponents]: InstanceType<GlobalComponents[Property]>
66+
}
67+
}"
5668
`;
5769

5870
exports[`dts > parseDeclaration - has icon component like <IMdi:diceD12> 1`] = `
@@ -107,7 +119,11 @@ declare module 'vue' {
107119
TestComp: typeof import('test/component/TestComp')['default']
108120
}
109121
}
110-
"
122+
declare global {
123+
type GlobalInstanceType = {
124+
[Property in keyof GlobalComponents]: InstanceType<GlobalComponents[Property]>
125+
}
126+
}"
111127
`;
112128

113129
exports[`dts > writeDeclaration - keep unused 1`] = `
@@ -131,7 +147,11 @@ declare module 'vue' {
131147
vSome: typeof import('test/directive/Some')['default']
132148
}
133149
}
134-
"
150+
declare global {
151+
type GlobalInstanceType = {
152+
[Property in keyof GlobalComponents]: InstanceType<GlobalComponents[Property]>
153+
}
154+
}"
135155
`;
136156

137157
exports[`dts > writeDeclaration 1`] = `
@@ -152,5 +172,9 @@ declare module 'vue' {
152172
vLoading: typeof import('test/directive/Loading')['default']
153173
}
154174
}
155-
"
175+
declare global {
176+
type GlobalInstanceType = {
177+
[Property in keyof GlobalComponents]: InstanceType<GlobalComponents[Property]>
178+
}
179+
}"
156180
`;

0 commit comments

Comments
 (0)