#I need some help implementing some kind of type guard
7 messages · Page 1 of 1 (latest)
!screenshot
Rather than screenshots, please provide either code formatted as:
```ts
// code here
```
Or even better, as an example on the TypeScript playground that is as simple as possible and reproduces the issue. This makes it easier to help you and increases the chances of getting an answer.
seems like you need some elses in there (or equivalent). otherwise execution will fall through even if prior cases are true
you could consider using a ternary. so like { condition1 ? output1 : condition2 ? output2 : defaultOutput }
- Don't send screenshots of your code. Send your code.
- You can use an
if-elsestatement. - You can also use a
switch-casestatement.
Since you're using Next.js, you can use a getStaticProps() or a getServerSideProps() function to setup your props. If you setup all of your DB queries as props, this will clean up your code quite a bit.
Oh thanks i wasn’t notified by discord about this messages, I solve this, I use
if ('key ' in variable) {
//do something
}