#Typescript is not showing the "X is possibly 'undefined'" error for some reason

20 messages · Page 1 of 1 (latest)

orchid plaza
#

This is not giving me an error for some reason (see screenshot). Although it does error in typescript playground (https://www.typescriptlang.org/play?#code/ATAuE8AcFNgMQPYOAXmAbwFAhAIwIYBOA-AFwbY574Be5AzqIQJYB2A5gNyUgC+3fbpQDGCVo2AAzJKgy9g+evCQCpSAHQFCm2pyA)

Is there some config that I need to enable? I'm confused by why this doesn't work for me.

polar trenchBOT
#

@orchid plaza Here's a shortened URL of your playground link! You can remove the full link from your message.

DaveJ#1185

Preview:```ts
type Foo = {
bar?: {
baz: string
}
}

const foo = {} as Foo
foo.bar.baz```

lilac basalt
#

uh because it is?

#

foo.bar is optional, so it's possibly undefined

#

it's from strictNullChecks i believe

#

oh i misread the issue, i had it reversed lmao

orchid plaza
#

I think your misunderstanding. I want to see the error but my editor is not showing the error

lilac basalt
#

i thought it wasn't erroring in the playground

#

yeah

#

you need to set strict/strictNullChecks

#

brainfart, mb

orchid plaza
#

Is it not enabled by default?

#

Will try setting it now.

#

Ok, that works. I assumed that a rule like this would be enabled by default. 🤔

#

!resolve

lilac basalt
#

!hb tsconfig reference

polar trenchBOT
lilac basalt
#

might want to check that

orchid plaza
#

Thanks, yeah I assumed strictNullChecks would be pretty important. Big source of "can not read x of undefined" errors.