-
I started the project with the Typescript starter. I was creating my own context and keep getting the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
This only happens when there's an attempt to destructure a non-array value. It's more likely that the Context isn't detected.
Destructuring without type-elimation causes this. Take note that It would be more helpful to know what your current code looks like. |
Beta Was this translation helpful? Give feedback.
-
Ah! I wasn't understanding that the error message was coming from the fact that useContext could return undefined. So, how do we fix this? I now see that in the typescript guide it talks about this. It mentions adding a ! to the useFunction. It also says this is bad. Is there a way we could actually get undefined here? Is there a better solution? I did create a repo with just the SolidJS ts template, and a counter context example here I got the error without the !, and it disappears with it. |
Beta Was this translation helpful? Give feedback.
Ah! I wasn't understanding that the error message was coming from the fact that useContext could return undefined. So, how do we fix this? I now see that in the typescript guide it talks about this. It mentions adding a ! to the useFunction. It also says this is bad. Is there a way we could actually get undefined here? Is there a better solution?
I did create a repo with just the SolidJS ts template, and a counter context example here I got the error without the !, and it disappears with it.