'typescript didn't report any error when function may return undefined
getStage may return undefined but didn't report any error.it will make my code crash.
const a = Math.random() > 0.4
function getStage(): string {
if(a) {
return ''
}
}
const str: string = getStage()
after tsc compiled
var a = Math.random() > 0.4;
function getStage() {
if (a) {
return '';
}
}
var str = getStage();
Solution 1:[1]
strictNullChecks - check if it off in your ts config
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Oleh Strokan |
