How to assign or return generic T that is constrained by union?
The error occurs because operations that involve a type parameter (including assignments and returns) must be valid for all types in its type set. In case of string | int, there isn’t a common operation to initialize their value from a string. However you still have a couple options: Type-switch on T You use the … Read more