How to convert `ContractId X` to `AnyContractId`?

In a DAML Trigger the emitCommands function takes a list of AnyContractIds as second argument to mark them as pending. I have a list of ContractId X that I want to pass in, how can I convert between the two?

To convert to AnyContractId you can use toAnyContractId. For converting from AnyContractId use fromAnyContractId. The latter returns an Optional and will return None if the contract id is of a different template.