Found after discussing this DefinitelyTyped issue: DefinitelyTyped/DefinitelyTyped#25731 (comment)
export interface Errored {
error: Error
value: null
}
export interface Succeeded<Value> {
error: null
value: Value
}
type Result<T> = Succeeded<T> | Errored;
declare function getVal<T>(x :T): Result<T>
let x = getVal("hello");
if (x.error === null) {
// vvvvvvv ERROR
x.value.toUpperCase();
}
Expected: No error
Actual: x.value is possibly null.