Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion packages/compiler-sfc/src/script/resolveType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,12 @@ function recordTypes(
}
} else if (stmt.type === 'TSModuleDeclaration' && stmt.global) {
for (const s of (stmt.body as TSModuleBlock).body) {
recordType(s, types, declares)
if (s.type === 'ExportNamedDeclaration' && s.declaration) {
// Handle export declarations inside declare global
recordType(s.declaration, types, declares)
} else {
recordType(s, types, declares)
}
}
}
} else {
Expand Down