@@ -128,7 +128,6 @@ import {
128128 isModuleDeclaration ,
129129 isOmittedExpression ,
130130 isPrivateIdentifier ,
131- isPropertySignature ,
132131 isSemicolonClassElement ,
133132 isSetAccessorDeclaration ,
134133 isSourceFile ,
@@ -722,7 +721,6 @@ export function transformDeclarations(context: TransformationContext) {
722721 | FunctionDeclaration
723722 | MethodDeclaration
724723 | GetAccessorDeclaration
725- | SetAccessorDeclaration
726724 | BindingElement
727725 | ConstructSignatureDeclaration
728726 | VariableDeclaration
@@ -741,46 +739,43 @@ export function transformDeclarations(context: TransformationContext) {
741739 // Literal const declarations will have an initializer ensured rather than a type
742740 return ;
743741 }
744- const shouldUseResolverType = node . kind === SyntaxKind . Parameter &&
745- ( resolver . isRequiredInitializedParameter ( node ) ||
746- resolver . isOptionalUninitializedParameterProperty ( node ) ) ;
747- if ( type && ! shouldUseResolverType ) {
742+ const shouldAddImplicitUndefined = node . kind === SyntaxKind . Parameter && resolver . requiresAddingImplicitUndefined ( node ) ;
743+ if ( type && ! shouldAddImplicitUndefined ) {
748744 return visitNode ( type , visitDeclarationSubtree , isTypeNode ) ;
749745 }
750- if ( ! getParseTreeNode ( node ) ) {
751- return type ? visitNode ( type , visitDeclarationSubtree , isTypeNode ) : factory . createKeywordTypeNode ( SyntaxKind . AnyKeyword ) ;
752- }
753- if ( node . kind === SyntaxKind . SetAccessor ) {
754- // Set accessors with no associated type node (from it's param or get accessor return) are `any` since they are never contextually typed right now
755- // (The inferred type here will be void, but the old declaration emitter printed `any`, so this replicates that)
756- return factory . createKeywordTypeNode ( SyntaxKind . AnyKeyword ) ;
757- }
746+
758747 errorNameNode = node . name ;
759748 let oldDiag : typeof getSymbolAccessibilityDiagnostic ;
760749 if ( ! suppressNewDiagnosticContexts ) {
761750 oldDiag = getSymbolAccessibilityDiagnostic ;
762751 getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode ( node ) ;
763752 }
764- if ( node . kind === SyntaxKind . VariableDeclaration || node . kind === SyntaxKind . BindingElement ) {
765- return cleanup ( resolver . createTypeOfDeclaration ( node , enclosingDeclaration , declarationEmitNodeBuilderFlags , symbolTracker ) ) ;
766- }
767- if (
768- node . kind === SyntaxKind . Parameter
769- || node . kind === SyntaxKind . PropertyDeclaration
770- || node . kind === SyntaxKind . PropertySignature
771- ) {
772- if ( isPropertySignature ( node ) || ! node . initializer ) return cleanup ( resolver . createTypeOfDeclaration ( node , enclosingDeclaration , declarationEmitNodeBuilderFlags , symbolTracker , shouldUseResolverType ) ) ;
773- return cleanup ( resolver . createTypeOfDeclaration ( node , enclosingDeclaration , declarationEmitNodeBuilderFlags , symbolTracker , shouldUseResolverType ) || resolver . createTypeOfExpression ( node . initializer , enclosingDeclaration , declarationEmitNodeBuilderFlags , symbolTracker ) ) ;
753+ let typeNode ;
754+ switch ( node . kind ) {
755+ case SyntaxKind . Parameter :
756+ case SyntaxKind . PropertySignature :
757+ case SyntaxKind . PropertyDeclaration :
758+ case SyntaxKind . BindingElement :
759+ case SyntaxKind . VariableDeclaration :
760+ typeNode = resolver . createTypeOfDeclaration ( node , enclosingDeclaration , declarationEmitNodeBuilderFlags , symbolTracker , shouldAddImplicitUndefined ) ;
761+ break ;
762+ case SyntaxKind . FunctionDeclaration :
763+ case SyntaxKind . ConstructSignature :
764+ case SyntaxKind . MethodSignature :
765+ case SyntaxKind . MethodDeclaration :
766+ case SyntaxKind . GetAccessor :
767+ case SyntaxKind . CallSignature :
768+ typeNode = resolver . createReturnTypeOfSignatureDeclaration ( node , node , declarationEmitNodeBuilderFlags , symbolTracker ) ;
769+ break ;
770+ default :
771+ Debug . assertNever ( node ) ;
774772 }
775- return cleanup ( resolver . createReturnTypeOfSignatureDeclaration ( node , enclosingDeclaration , declarationEmitNodeBuilderFlags , symbolTracker ) ) ;
776773
777- function cleanup ( returnValue : TypeNode | undefined ) {
778- errorNameNode = undefined ;
779- if ( ! suppressNewDiagnosticContexts ) {
780- getSymbolAccessibilityDiagnostic = oldDiag ;
781- }
782- return returnValue || factory . createKeywordTypeNode ( SyntaxKind . AnyKeyword ) ;
774+ errorNameNode = undefined ;
775+ if ( ! suppressNewDiagnosticContexts ) {
776+ getSymbolAccessibilityDiagnostic = oldDiag ! ;
783777 }
778+ return typeNode ?? factory . createKeywordTypeNode ( SyntaxKind . AnyKeyword ) ;
784779 }
785780
786781 function isDeclarationAndNotVisible ( node : NamedDeclaration ) {
0 commit comments