Having an issue with TypeScript (TS2531) and its non-null type checking. Here's the scenario:
if (this.formGroup.get('inseeActivityCode') !== null) {
mergedCompanyActivity.inseeActivityCode = this.formGroup.get('inseeActivityCode').value; // => TS2531: Object is possibly 'null'.
}
Despite explicitly checking for inseeActivityCodeControl
not being null, TypeScript still throws TS2531 error when accessing inseeActivityCodeControl.value
. This is confusing as the condition should prevent this from happening. Can anyone shed light on why TypeScript continues to raise this error and offer a solution that doesn't involve using the !
assertion operator?
Thanks in advance!