Skip to content

Commit e4091fe

Browse files
authored
fix(compiler-sfc): handle indexed access types in declare global blocks (#14260)
close #14236
1 parent 6a1bb50 commit e4091fe

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,26 @@ describe('resolveType', () => {
15251525
})
15261526
})
15271527

1528+
test('declare global with indexed access type', () => {
1529+
const files = {
1530+
'/global.d.ts': `
1531+
declare global {
1532+
type Options = {
1533+
code: {
1534+
selected: boolean
1535+
}
1536+
}
1537+
}`,
1538+
}
1539+
const { props } = resolve(`defineProps<Options["code"]>()`, files, {
1540+
globalTypeFiles: Object.keys(files),
1541+
})
1542+
1543+
expect(props).toStrictEqual({
1544+
selected: ['Boolean'],
1545+
})
1546+
})
1547+
15281548
// #9871
15291549
test('shared generics with different args', () => {
15301550
const files = {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,18 @@ function recordType(
13991399
case 'TSInterfaceDeclaration':
14001400
case 'TSEnumDeclaration':
14011401
case 'TSModuleDeclaration': {
1402+
// Handle `declare global { ... }` blocks by recursively processing their contents
1403+
if (node.type === 'TSModuleDeclaration' && node.global) {
1404+
const body = node.body as TSModuleBlock
1405+
for (const s of body.body) {
1406+
if (s.type === 'ExportNamedDeclaration' && s.declaration) {
1407+
recordType(s.declaration, types, declares)
1408+
} else {
1409+
recordType(s, types, declares)
1410+
}
1411+
}
1412+
break
1413+
}
14021414
const id = overwriteId || getId(node.id)
14031415
let existing = types[id]
14041416
if (existing) {

0 commit comments

Comments
 (0)