5
5
ArrowFunction ,
6
6
Block ,
7
7
CallExpression ,
8
+ canHaveSymbol ,
8
9
CharacterCodes ,
9
10
ClassLikeDeclaration ,
10
11
CodeFixContextBase ,
@@ -38,8 +39,10 @@ import {
38
39
IntersectionType ,
39
40
isArrowFunction ,
40
41
isAutoAccessorPropertyDeclaration ,
42
+ isConstructorTypeNode ,
41
43
isFunctionDeclaration ,
42
44
isFunctionExpression ,
45
+ isFunctionTypeNode ,
43
46
isGetAccessorDeclaration ,
44
47
isIdentifier ,
45
48
isImportTypeNode ,
@@ -64,6 +67,7 @@ import {
64
67
NodeArray ,
65
68
NodeBuilderFlags ,
66
69
NodeFlags ,
70
+ nodeIsSynthesized ,
67
71
nullTransformationContext ,
68
72
ObjectFlags ,
69
73
ObjectLiteralExpression ,
@@ -84,6 +88,7 @@ import {
84
88
some ,
85
89
SourceFile ,
86
90
Symbol ,
91
+ SymbolAccessibility ,
87
92
SymbolFlags ,
88
93
SymbolTracker ,
89
94
SyntaxKind ,
@@ -363,6 +368,7 @@ export function createSignatureDeclarationFromSignature(
363
368
) {
364
369
const program = context . program ;
365
370
const checker = program . getTypeChecker ( ) ;
371
+ const resolver = checker . getEmitResolver ( ) ;
366
372
const scriptTarget = getEmitScriptTarget ( program . getCompilerOptions ( ) ) ;
367
373
const isJs = isInJSFile ( enclosingDeclaration ) ;
368
374
const flags =
@@ -417,6 +423,9 @@ export function createSignatureDeclarationFromSignature(
417
423
type = importableReference . typeNode ;
418
424
importSymbols ( importAdder , importableReference . symbols ) ;
419
425
}
426
+ else if ( ! isDeclTypeSymbolVisible ( parameterDecl . type ) ) {
427
+ type = factory . createKeywordTypeNode ( SyntaxKind . AnyKeyword ) ;
428
+ }
420
429
}
421
430
return factory . updateParameterDeclaration (
422
431
parameterDecl ,
@@ -455,6 +464,23 @@ export function createSignatureDeclarationFromSignature(
455
464
return factory . updateFunctionDeclaration ( signatureDeclaration , modifiers , signatureDeclaration . asteriskToken , tryCast ( name , isIdentifier ) , typeParameters , parameters , type , body ?? signatureDeclaration . body ) ;
456
465
}
457
466
return undefined ;
467
+
468
+ function isDeclTypeSymbolVisible ( declType : TypeNode | undefined ) {
469
+ if ( ! declType || ! canHaveSymbol ( declType ) ) {
470
+ return true ;
471
+ }
472
+
473
+ if ( ! declType . symbol ) {
474
+ // These nodes won't have a symbol when generated via a code fix, so we treat them as an exception.
475
+ if ( isFunctionTypeNode ( declType ) || isConstructorTypeNode ( declType ) ) {
476
+ return nodeIsSynthesized ( declType ) ;
477
+ }
478
+ return false ;
479
+ }
480
+
481
+ const access = resolver . isSymbolAccessible ( declType . symbol , declType , declType . symbol . flags , /* shouldComputeAliasToMarkVisible */ true ) ;
482
+ return access . accessibility === SymbolAccessibility . Accessible ;
483
+ }
458
484
}
459
485
460
486
/** @internal */
0 commit comments