Issue
Let's take this example:
function maybeString(a: number): string | undefined {
if (a > 5) {
return 'ok';
}
}
This is valid Typescript.
Is there a configuration to force this code to be:
function maybeString(a: number): string | undefined {
if (a > 5) {
return 'ok';
} else {
return undefined;
}
}
So always making the return undefined necessary and explicit?
Solution
Normally that should already lead to a TS error (link to TS playground). The error should be "Not all code paths return a value.ts(7030)".
Maybe check your tsconfig file and set "noImplicitReturns" to true. If not yet true, this should enable such warnings.
tsconfig.json:
{
"compilerOptions": {
"noImplicitReturns": true
}
}
Answered By - ddemand
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.