Let's start by replicating the issue I am facing.
Begin by creating a new Angular project
ng new ng-ts-strict-issue cd ng-ts-strict-issue
Update
compilerOptions
intsconfig.json
. Change the value ofstrict
tofalse
.{ ... "compilerOptions": { ... "strict": false, ... }, ... }
Include a new method in the
app.component.ts
.test(p: string): string | null | undefined { if (p === 'test') { return; } return null; }
Execute
ng build
⠼ Building...✘ [ERROR] TS7030: Not all code paths return a value. [plugin angular-compiler] src/app/app.component.ts:17:6: 17 │ return; ╵ ~~~~~~ Application bundle generation failed. [3.905 seconds]
I am familiar with this error. It is associated with the "noImplicitReturns"
: true setting in the tsconfig.json
file. Disabling this option can resolve the problem.
However, my query is why does the return;
statement trigger the
TS7030: Not all code paths return a value.
error only when the strict
mode is set to false
? All code paths have already been accounted for. Why is there a violation of the noImplicitReturns
rule?