|
|
|
|
|
by JCTheDenthog
30 days ago
|
|
Simple example that I use often when writing API clients: In current C# I usually do something like public class ApiResponse<T>
{
public T? Response { get; set; }
public bool IsSuccessful { get; set; }
public ErrorResponse Error { get; set; }
} This means I have to check that IsSuccessful is true (and/or that Response is not null). But more importantly, it means my imbecile coworkers who never read my documentation need to do so as well otherwise they're going to have a null reference exception in prod because they never actually test their garbage before pushing it to prod. And I get pulled into a 4 hour meeting to debug and solve the issue as a result. With union types, I can return a union of the types T and ErrorResponse and save myself massive headaches. |
|