-
I have the following code defined in an F# class: member private this.ExecuteRequest<'TRequest, 'TResponse>
(endpoint: string, request: 'TRequest')
: Task<'TResponse> =
let jsonRequestBody =
JsonSerializer.Serialize<'TRequest>(request, jsonSerializerOptions) And it produces the following strange warning:
I have spent over two hours trying to remove it. Even poked around with various LLMs but they were rapidly out of their depth. Here is the challenge: if i remove the type hint in let! myVal = this.ExecuteRequest<RequestType1, ResponseType1>("myendpoint", myRequest) the second method calling: let! myVal = this.ExecuteRequest<RequestType2, ResponseType2>("myendpoint", myRequest2) produces a compiler error saying that myRequest2 was expected to be of type The compiler errors at the callers sites disappear when i add a type hint to I'll be honest, I've been very frustrated to run into this issue, while generic functions, generalizations etc... are supposed to be the strong side of F#, and such code would be trivial in C#. I suspect it has to do with interop between F# generics and C# generics, but still, very frustrating to need to bang my head on something I expected would take me 1 minute. And I still don't know what's going on. I resorted to disabling the warning for the whole file which is not ideal at all but this is the only option i have apparently. I would have preferred to address the root cause if possible. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Which would mean |
Beta Was this translation helpful? Give feedback.
You have a typo here:
Which would mean
'TRequest'
and'TRequest
are two different type parameters 😄