The actual subscript works because you're directly converting String
to String?
, which is different from converting Just<String>
to Just<String?>
, given that generic and its placeholders are invariant in Swift.
In theory, assign
would work as you're only assigning to it (as opposing to reading from it), but you'd at least need to annotate the covariance with something similar to
extension Just {
func assign<R, SubValue>(_: ...KeyPath<R, Value>, value: SubValue)
where SubValue: Value { ... }
}
which is not possible right now. With the status quo, you need to provide the exact type. At best you'd have two overloads, one with non-optional, another with optional (though that could impact type-checker performance).