How to handle possibly undefined objects in initial create #2907
-
Hey @dai-shi , quick question. When creating a store using typescript, how do you handle objects that could be undefined. For example, if i have an object in the store, say Person, but it does not have any initial data that i can set it to, and it may never get set at all, do i just do an empty object and cast it? like person: {} as Person, or just leave it as undefined, like person: undefined (or just leave it out of the create object) Also, if you have a complex object, that does not have any initial data, is it fine to cast the empty object as the type, OR is it best to create a large initial object and take the best logical guesses at the default property values? thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's not fine if you want to get type checks. I would do this |
Beta Was this translation helpful? Give feedback.
It's not fine if you want to get type checks. I would do this
person: undefined as Person | undefined
.