Closed
Description
TypeScript Version: 2.1.5
Code
Minimal example that compiles just fine:
let x: Promise<string | undefined> = Promise.resolve(undefined);
let y: Promise<string> = x;
Small usage example in which I encountered the bug:
interface ITest {
test(): Promise<string>;
}
class Test implements ITest{
test(): Promise<string | undefined> {
return Promise.resolve(undefined);
}
}
var test = new Test();
test.test().then(console.log);
Expected behavior:
A compile error: the type Promise<string | undefined>
does not match the type Promise<string>
. I should not be able to cast undefined
to string
.
Actual behavior:
No errors.