You can write that line better than that, but you cannot get rid of the String?
, because AnyKeyPath and PartialKeyPath don't provide their Value
to the type system. nil
is strongly-typed, and so I'm having trouble imagining where @bdkjones thinks it could be acquiring that.
foo[keyPath: kps.first as! ReferenceWritableKeyPath] = nil as String?
foo[keyPath: kps.first as! ReferenceWritableKeyPath] = String?.none
typedNil(of: type(of: foo.name))
could be rewritten as
type(of: \Foo.name).Value.none
extension KeyPath { typealias Value = Value }
But that's the same as
foo.name = nil