ScopedTypeVariables and TypeApplications

Is there a limitation on using a scoped type variable in a visible type application? For example, the following doesn’t compile with “error:Not in scope: type variable ‘t’”:

qck : TemplateKey t k => forall t k. Proxy t -> Party -> k -> Script (Optional (ContractId t, t))
qck _ = queryContractKey @t

Context: I’d like to write a class method that queries for a template type t in the class head, but that doesn’t work, and neither does this standalone declaration with an explicit forall.

What am I doing wrong?

Your forall is too far nested down. You need to pull it outside the constraint. Then your example compiles perfectly fine:

qck : forall t k. TemplateKey t k => Proxy t -> Party -> k -> Script (Optional (ContractId t, t))
qck _ = queryContractKey @t

Thanks, that worked.