maus
maus

Reputation: 190

VS Code does not warn for possible undefined object

I'm creating this React hook, which exposes a user object. Inside the hook I'm defining the type as either 'CognitoUserInterface | undefined'. Since the object will be undefined during initialization.

When I use this hook inside a component, VS code does not warn me that the object will possibly be undefined. I've created an example in CodeSandbox which does however warn. Both use the same code, and same version of TypeScript.

Is this some bug in VS Code? I already tried restarting the TypeScript server. What else could be going on?

My VS Code (not underlining the console.log function on the right)

Screenshot of my VS Code environment

CodeSandbox (does underline the console.log function, although being on same TypeScript version)

Screenshot of the CodeSandbox environment

CodeSandbox

Upvotes: 0

Views: 1147

Answers (1)

maus
maus

Reputation: 190

Based on the comment by Mohammad I saw 'strict' mode was false in my VSCode environment. Enabling this fixed my issue :)

Upvotes: 3

Related Questions