function example(obj: { prop: string | number }): string {
if (typeof obj.prop === 'string') {
mutatesProp(obj);
return obj.prop;
} else {
return "default";
}
}
function mutatesProp(obj) {
obj.prop = 42;
}
example({ prop: 'test' });
No errors
This is what you get even with the
--strictNullChecks
flag
6: return obj.prop;
^ number. This type is incompatible with the expected return type of
3: function example(obj: { prop: string | number }): string {
^ string