Function returning a generic with different type parameter

Error message seems strange, but what you are doing is returning Test<String>.

// it compiles.

struct Test<X> {
    var value: X
}

extension Test {
    func create() -> Test<String> {
        let value = "\(self.value)"   // this is value of type String
        return Test<String>(value: value)
    }
}

In function declaration, type parameters are decided by the user, not function itself.

1 Like