Skip to content

Commit 35da3c6

Browse files
authored
fix(compiler-sfc): support global augments with named exports (#13789)
1 parent 8f6b505 commit 35da3c6

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,33 @@ describe('resolveType', () => {
13421342
expect(deps && [...deps]).toStrictEqual(Object.keys(files))
13431343
})
13441344

1345+
test('global types with named exports', () => {
1346+
const files = {
1347+
'/global.d.ts': `
1348+
declare global {
1349+
export interface ExportedInterface { foo: number }
1350+
export type ExportedType = { bar: boolean }
1351+
}
1352+
export {}
1353+
`,
1354+
}
1355+
1356+
const globalTypeFiles = { globalTypeFiles: Object.keys(files) }
1357+
1358+
expect(
1359+
resolve(`defineProps<ExportedInterface>()`, files, globalTypeFiles)
1360+
.props,
1361+
).toStrictEqual({
1362+
foo: ['Number'],
1363+
})
1364+
1365+
expect(
1366+
resolve(`defineProps<ExportedType>()`, files, globalTypeFiles).props,
1367+
).toStrictEqual({
1368+
bar: ['Boolean'],
1369+
})
1370+
})
1371+
13451372
test('global types with ambient references', () => {
13461373
const files = {
13471374
// with references

packages/compiler-sfc/src/script/resolveType.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,12 @@ function recordTypes(
12961296
}
12971297
} else if (stmt.type === 'TSModuleDeclaration' && stmt.global) {
12981298
for (const s of (stmt.body as TSModuleBlock).body) {
1299-
recordType(s, types, declares)
1299+
if (s.type === 'ExportNamedDeclaration' && s.declaration) {
1300+
// Handle export declarations inside declare global
1301+
recordType(s.declaration, types, declares)
1302+
} else {
1303+
recordType(s, types, declares)
1304+
}
13001305
}
13011306
}
13021307
} else {

0 commit comments

Comments
 (0)