@@ -1689,7 +1689,7 @@ public struct BridgeJSLink {
16891689 // Look up the enum to get its tsFullPath
16901690 for skeleton in exportedSkeletons {
16911691 for enumDef in skeleton . enums {
1692- if enumDef . name == name || enumDef . swiftCallName == name {
1692+ if enumDef . swiftCallName == name {
16931693 // Use the stored tsFullPath which has the full namespace
16941694 switch type {
16951695 case . namespaceEnum :
@@ -1707,7 +1707,7 @@ public struct BridgeJSLink {
17071707 case . swiftStruct ( let name ) :
17081708 for skeleton in exportedSkeletons {
17091709 for structDef in skeleton . structs {
1710- if structDef . name == name || structDef . swiftCallName == name {
1710+ if structDef . swiftCallName == name {
17111711 return structDef . tsFullPath
17121712 }
17131713 }
@@ -1716,12 +1716,14 @@ public struct BridgeJSLink {
17161716 case . swiftHeapObject ( let name ) :
17171717 for skeleton in exportedSkeletons {
17181718 for klass in skeleton . classes {
1719- if klass . name == name || klass . swiftCallName == name {
1719+ if klass . swiftCallName == name {
17201720 return klass . name
17211721 }
17221722 }
17231723 }
17241724 return type . tsType
1725+ case . closure ( let signature , _) :
1726+ return signature . renderTSFunctionType { resolveTypeScriptType ( $0 , exportedSkeletons : exportedSkeletons ) }
17251727 case . alias ( _, let underlying ) :
17261728 return resolveTypeScriptType ( underlying , exportedSkeletons : exportedSkeletons )
17271729 case . nullable ( let wrapped , let kind ) :
@@ -3761,7 +3763,8 @@ extension BridgeJSLink {
37613763 let abiName = getter . abiName ( context : nil )
37623764 let funcLines = thunkBuilder . renderFunction ( name : abiName )
37633765 if getter . from == nil {
3764- importObjectBuilder . appendDts ( [ " readonly \( renderTSPropertyName ( jsName ) ) : \( getter . type . tsType ) ; " ] )
3766+ importObjectBuilder . appendDts ( [ " readonly \( renderTSPropertyName ( jsName ) ) : \( getter . type . tsType ) ; " ]
3767+ )
37653768 }
37663769 importObjectBuilder . assignToImportObject ( name : abiName , function : funcLines )
37673770 }
@@ -4230,6 +4233,17 @@ struct BridgeJSLinkError: Error {
42304233 let message : String
42314234}
42324235
4236+ extension ClosureSignature {
4237+ fileprivate func renderTSFunctionType ( renderType : ( BridgeType ) -> String ) -> String {
4238+ let renderedParameters = parameters . enumerated ( ) . map { index , parameter in
4239+ " arg \( index ) : \( renderType ( parameter ) ) "
4240+ } . joined ( separator : " , " )
4241+ let renderedReturnType = renderType ( returnType )
4242+ let returnTypeWithEffect = isAsync ? " Promise< \( renderedReturnType ) > " : renderedReturnType
4243+ return " ( \( renderedParameters ) ) => \( returnTypeWithEffect ) "
4244+ }
4245+ }
4246+
42334247extension BridgeType {
42344248 var tsType : String {
42354249 switch self {
@@ -4271,12 +4285,7 @@ extension BridgeType {
42714285 case . swiftProtocol ( let name ) :
42724286 return name
42734287 case . closure ( let signature , _) :
4274- let paramTypes = signature . parameters . enumerated ( ) . map { index , param in
4275- " arg \( index ) : \( param . tsType ) "
4276- } . joined ( separator : " , " )
4277- let returnTS =
4278- signature . isAsync ? " Promise< \( signature . returnType . tsType ) > " : signature . returnType . tsType
4279- return " ( \( paramTypes ) ) => \( returnTS ) "
4288+ return signature . renderTSFunctionType { $0 . tsType }
42804289 case . array ( let elementType ) :
42814290 let inner = elementType . tsType
42824291 if inner . contains ( " | " ) || inner . contains ( " => " ) {
0 commit comments