File tree Expand file tree Collapse file tree 4 files changed +43
-1
lines changed Expand file tree Collapse file tree 4 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 1
1
# Unreleased
2
2
3
+ ### Features
4
+
5
+ - Added support for documenting a module's global declarations as its exports if it contains no real exports.
6
+
3
7
### Bug Fixes
4
8
5
9
- Restore support for TS 4.0 through 4.5, #1945 .
Original file line number Diff line number Diff line change @@ -469,7 +469,7 @@ function getSymbolForModuleLike(
469
469
470
470
function getExports (
471
471
context : Context ,
472
- node : ts . SourceFile | ts . ModuleBlock ,
472
+ node : ts . SourceFile ,
473
473
symbol : ts . Symbol | undefined
474
474
) : ts . Symbol [ ] {
475
475
let result : ts . Symbol [ ] ;
@@ -496,6 +496,27 @@ function getExports(
496
496
result = context . checker
497
497
. getExportsOfModule ( symbol )
498
498
. filter ( ( s ) => ! hasAllFlags ( s . flags , ts . SymbolFlags . Prototype ) ) ;
499
+
500
+ if ( result . length === 0 ) {
501
+ const globalDecl = node . statements . find (
502
+ ( s ) =>
503
+ ts . isModuleDeclaration ( s ) &&
504
+ s . flags & ts . NodeFlags . GlobalAugmentation
505
+ ) ;
506
+
507
+ if ( globalDecl ) {
508
+ const globalSymbol = context . getSymbolAtLocation ( globalDecl ) ;
509
+ if ( globalSymbol ) {
510
+ result = context . checker
511
+ . getExportsOfModule ( globalSymbol )
512
+ . filter ( ( exp ) =>
513
+ exp . declarations ?. some (
514
+ ( d ) => d . getSourceFile ( ) === node
515
+ )
516
+ ) ;
517
+ }
518
+ }
519
+ }
499
520
} else {
500
521
// Global file with no inferred top level symbol, get all symbols declared in this file.
501
522
const sourceFile = node . getSourceFile ( ) ;
Original file line number Diff line number Diff line change @@ -81,6 +81,14 @@ export const behaviorTests: Record<
81
81
"WithoutReadonlyNumeric"
82
82
) ;
83
83
} ,
84
+
85
+ declareGlobal ( project ) {
86
+ equal (
87
+ project . children ?. map ( ( c ) => c . name ) ,
88
+ [ "DeclareGlobal" ]
89
+ ) ;
90
+ } ,
91
+
84
92
duplicateHeritageClauses ( project ) {
85
93
const b = query ( project , "B" ) ;
86
94
equal ( b . extendedTypes ?. map ( String ) , [ "A" ] ) ;
Original file line number Diff line number Diff line change
1
+ import { SyntaxKind } from "typescript" ;
2
+
3
+ declare global {
4
+ interface DeclareGlobal {
5
+ method ( kind : SyntaxKind ) : void ;
6
+ }
7
+ }
8
+
9
+ namespace NotIncluded { }
You can’t perform that action at this time.
0 commit comments