The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
#""object.property" is possibly undefined" in function only regardless of check
3 messages · Page 1 of 1 (latest)
@dull delta Here's a shortened URL of your playground link! You can remove the full link from your message.
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)
...```
You can choose specific lines to embed by selecting them before copying the link.
myFunction could theoretically be called later on at any point in your program, and somebody could do myStructure.myOtherProp = undefined in the meantime