diff --git a/src/TypedSignalR.Client.TypeScript.Analyzer/InterfaceAnalyzer.cs b/src/TypedSignalR.Client.TypeScript.Analyzer/InterfaceAnalyzer.cs index 895b4f8..1ee9a97 100644 --- a/src/TypedSignalR.Client.TypeScript.Analyzer/InterfaceAnalyzer.cs +++ b/src/TypedSignalR.Client.TypeScript.Analyzer/InterfaceAnalyzer.cs @@ -226,6 +226,11 @@ private static void AnalyzeReceiverInterface( foreach (var parameter in method.Parameters) { + if (SymbolEqualityComparer.Default.Equals(parameter.Type, specialSymbols.CancellationTokenSymbol)) + { + continue; + } + ValidateType(context, parameter.Type, parameter.Locations[0], supportTypeSymbols, transpilationSourceAttributeSymbol); } } diff --git a/src/TypedSignalR.Client.TypeScript/Templates/ApiTemplate.cs b/src/TypedSignalR.Client.TypeScript/Templates/ApiTemplate.cs index 080b320..49643d3 100644 --- a/src/TypedSignalR.Client.TypeScript/Templates/ApiTemplate.cs +++ b/src/TypedSignalR.Client.TypeScript/Templates/ApiTemplate.cs @@ -138,7 +138,7 @@ public constructor( this.Write(" const __"); this.Write(this.ToStringHelper.ToStringWithCulture(method.Name.Format(Options.NamingStyle))); this.Write(" = "); - this.Write(this.ToStringHelper.ToStringWithCulture(method.WrapLambdaExpressionSyntax(Options))); + this.Write(this.ToStringHelper.ToStringWithCulture(method.WrapLambdaExpressionSyntax(SpecialSymbols, Options))); this.Write(";\r\n"); } this.Write("\r\n"); diff --git a/src/TypedSignalR.Client.TypeScript/Templates/ApiTemplate.tt b/src/TypedSignalR.Client.TypeScript/Templates/ApiTemplate.tt index 9a7b1d0..e2fa9a6 100644 --- a/src/TypedSignalR.Client.TypeScript/Templates/ApiTemplate.tt +++ b/src/TypedSignalR.Client.TypeScript/Templates/ApiTemplate.tt @@ -111,7 +111,7 @@ class <#= receiverType.Name #>_Binder implements ReceiverRegister<<#= receiverTy public readonly register = (connection: HubConnection, receiver: <#= receiverType.Name #>): Disposable => { <# foreach(var method in receiverType.Methods) { #> - const __<#= method.Name.Format(Options.NamingStyle) #> = <#= method.WrapLambdaExpressionSyntax(Options) #>; + const __<#= method.Name.Format(Options.NamingStyle) #> = <#= method.WrapLambdaExpressionSyntax(SpecialSymbols, Options) #>; <# } #> <# foreach(var method in receiverType.Methods) { #> diff --git a/src/TypedSignalR.Client.TypeScript/Templates/MethodSymbolExtensions.cs b/src/TypedSignalR.Client.TypeScript/Templates/MethodSymbolExtensions.cs index d35ce2c..6d1afbb 100644 --- a/src/TypedSignalR.Client.TypeScript/Templates/MethodSymbolExtensions.cs +++ b/src/TypedSignalR.Client.TypeScript/Templates/MethodSymbolExtensions.cs @@ -6,14 +6,14 @@ namespace TypedSignalR.Client.TypeScript.Templates; internal static class MethodSymbolExtensions { - public static string WrapLambdaExpressionSyntax(this IMethodSymbol methodSymbol, ITypedSignalRTranspilationOptions options) + public static string WrapLambdaExpressionSyntax(this IMethodSymbol methodSymbol, SpecialSymbols specialSymbols, ITypedSignalRTranspilationOptions options) { if (methodSymbol.Parameters.Length == 0) { return $"() => receiver.{methodSymbol.Name.Format(options.MethodStyle)}()"; } - var parameters = ParametersToTypeArray(methodSymbol, options); + var parameters = ParametersToTypeArray(methodSymbol, specialSymbols, options); return $"(...args: {parameters}) => receiver.{methodSymbol.Name.Format(options.MethodStyle)}(...args)"; } @@ -78,9 +78,12 @@ private static string ReturnTypeToTypeScriptString(this IMethodSymbol methodSymb return TypeMapper.MapTo(methodSymbol.ReturnType, options); } - private static string ParametersToTypeArray(IMethodSymbol methodSymbol, ITypedSignalRTranspilationOptions options) + private static string ParametersToTypeArray(IMethodSymbol methodSymbol, SpecialSymbols specialSymbols, ITypedSignalRTranspilationOptions options) { - var parameters = methodSymbol.Parameters.Select(x => TypeMapper.MapTo(x.Type, options)); + var parameters = methodSymbol.Parameters + .Where(x => !SymbolEqualityComparer.Default.Equals(x.Type, specialSymbols.CancellationTokenSymbol)) + .Select(x => TypeMapper.MapTo(x.Type, options)); + return $"[{string.Join(", ", parameters)}]"; }