Let's say I have code along the lines of this:
function defaultIt(s: MaybeString): string {
if (typeof s.content === "string") {
return s.content;
}
return "";
}
class MaybeString {
content: string|void;
}
Correct me if I'm wrong, but I believe this is about as type-safe as you can get; any possible input that fits MaybeString
will result in a string. However, TypeScript gives me an error: Type 'string | void' is not assignable to type 'string'
.
How can I get TypeScript to recognize that I've removed ambiguity by checking the type?
Thanks!