-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'Generic parameter 'T' could not be inferred' when stubbing protocol with generics #401
Comments
Did you ever find a solution to this problem? I'm experiencing the same thing. |
Believe I figured it out in case this helps someone in the future: /// A protocol that defines the interface for managing active tasks for a specific type of GraphQL query.
public protocol ActiveTaskManager {
/// Retrieves an existing task for the given key or creates and stores a new task if none exists.
/// - Parameters:
/// - key: The unique key identifying the task.
/// - newTask: A closure that creates the new task if no existing task is found. This closure must be `@escaping`
/// to be stored and called later, and `@Sendable` to ensure it can be safely executed concurrently.
/// - Returns: The existing or newly created task associated with the given key.
func getOrSetTask<T: GraphQLQuery>(
for key: String,
queryType: T.Type,
newTask: @escaping @Sendable () async throws -> ServerResponse<T.Response>
) async -> Task<ServerResponse<T.Response>, Error>
/// Removes the task associated with the given key.
/// - Parameter key: The unique key identifying the task to be removed.
func removeTask(for key: String) async
}
// how to stub in tests:
stub(activeTaskManagerProvider) { stub in
stub.getManager(for: any(PlaidLinkTokenQuery.Type.self)).thenReturn(DefaultActiveTasksManager())
} |
@chaseklingelzen so specifying the type explicitly in the |
@MatyasKriz! Exactly. I think using |
Oh I was just curious, no issues here. 🙂 Thanks for your investigation. |
Hey guys,
I'm facing problems when setting up stubbing for the following protocol:
I'm currently saving Date objects in that Storage, so my test setup is as follows:
However, I'm getting the following error for the
when(stub...
line:So I'm not sure if providing the type (Date) in the
.then
command is enough to make thewhen(stub...
resolve the generic type? I'm also not sure, I'm using the block syntax correctly here? I'm trying to make calls to theload
function return a date in the completion block.Any help or hints would be highly appreciated!
The text was updated successfully, but these errors were encountered: