#I need some help implementing some kind of type guard

7 messages · Page 1 of 1 (latest)

burnt silo
#

Hi there, I am trying to check the type of a response but I am a bit stuck. 😅 I am very new to TS, so pardon my shoddy code it was a solution that I made but iam not happy with it .
I am using nextJS btw.

mint sparrow
#

!screenshot

vernal violetBOT
#
`!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.

mint sparrow
#

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 }

earnest maple
#
  1. Don't send screenshots of your code. Send your code.
  2. You can use an if-else statement.
  3. You can also use a switch-case statement.

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.

burnt silo