Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript error TS2532, Object is possible undefined

I installed WebStorm 2020.1 yesterday.

Suddenly I got a bunch of TS2532 errors.

enter image description here

How can this be "possible undefined"? The selectedOwner && protects against that?

I tried to disabled this stupid error with "strictNullChecks": false, but has no effect.

like image 351
Joe Avatar asked Dec 07 '25 07:12

Joe


1 Answers

Webstorm is occasionally slow to propagate the changes.

What I would recommend is to check and ensure that you the webstorm TypeSript service is using the right TypeScript version, and that it is using the right tsconfig.json file on your project.

On the Webstorm menu, go to Preferences -> Languages & Frameworks -> TypeScript.

Ensure that is is loading TypeScript from your project's node_modules, and not anywhere else. In addition, the compile scope should be set to Project Files

It may also help if you restart TypeScript service.

In addition, if you are using TypeScript 3.7.5 and above, you can simplify your conditional rendering by using optional chaining:

selectedLocalOwner?.id && .....
like image 116
wentjun Avatar answered Dec 09 '25 00:12

wentjun