Towards a safer SwiftUI environment
@EnvironmentObject is currently prone to runtime errors. If a view uses an environment object of a type that was not injected using
fatalError occurs. This document sketches a design that would support compile-time checking of environment object usage. It requires a few language enhancements.
Tuple intersection types
Swift's protocol composition types such as
Protocol1 & Protocol2 are a form of intersection types. Other forms of intersection types are possible. For example, Flow has object intersection types. Tuple intersection types for Swift would be very similar to these.
Below, you can see the examples in the Flow documentation converted to Swift's tuples: