fix(compiler-sfc): support global augments with named exports (#13789)

This commit is contained in:
Daniel Roe 2025-09-02 10:03:16 +01:00 committed by GitHub
parent 8f6b505051
commit 35da3c6dcb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 1 deletions

View File

@ -1342,6 +1342,33 @@ describe('resolveType', () => {
expect(deps && [...deps]).toStrictEqual(Object.keys(files))
})
test('global types with named exports', () => {
const files = {
'/global.d.ts': `
declare global {
export interface ExportedInterface { foo: number }
export type ExportedType = { bar: boolean }
}
export {}
`,
}
const globalTypeFiles = { globalTypeFiles: Object.keys(files) }
expect(
resolve(`defineProps<ExportedInterface>()`, files, globalTypeFiles)
.props,
).toStrictEqual({
foo: ['Number'],
})
expect(
resolve(`defineProps<ExportedType>()`, files, globalTypeFiles).props,
).toStrictEqual({
bar: ['Boolean'],
})
})
test('global types with ambient references', () => {
const files = {
// with references

View File

@ -1296,9 +1296,14 @@ function recordTypes(
}
} else if (stmt.type === 'TSModuleDeclaration' && stmt.global) {
for (const s of (stmt.body as TSModuleBlock).body) {
if (s.type === 'ExportNamedDeclaration' && s.declaration) {
// Handle export declarations inside declare global
recordType(s.declaration, types, declares)
} else {
recordType(s, types, declares)
}
}
}
} else {
recordType(stmt, types, declares)
}