#""object.property" is possibly undefined" in function only regardless of check

3 messages · Page 1 of 1 (latest)

worldly jackalBOT
#

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

clauz2942#0

Preview:```ts
type MyStructure {
myProp: Record<string, string>
myOtherProp?: Record<string, string>
}

const myStructure: MyStructure = { myProp: { "a": "b"}, myOtherProp: {"c": "d"} }

if(myStructure.myOtherProp) {

// can access both props as expected
console.log(myStructure.myProp.a)

...```

ivory rune
#

myFunction could theoretically be called later on at any point in your program, and somebody could do myStructure.myOtherProp = undefined in the meantime