To not loose type information, you need to add it to your protocol, which is what associatedtype is for. Your initial version isn't saving this information, as it actually declares any Codable (I really wish Swift 6 didn't end up keeping this implicit), stating that you expect just any type and don't care about specific one. some isn't working for the same reason, plus it won't give you any upsides in that case as you need to preserve concrete type information in your code.