Type of return from await
getting a TS error stating "34:9 Error: Unsafe assignment of an any value." on my await in getServerSideProps. Tried to scour the docs for a solution but can't find anywhere where someone sets a type that works for me await.
getAudit is a JS function, not TS (yet). Any ideas on how I should best solve this?
I have the "correct" props for my render function in the page
16 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Tried to do "
const audit= await getAudit(
/granskninger/${params.query.slug}) as Props;
"but got the same error, also tried
const audit: Props = await getAudit(
/granskninger/${params.query.slug});
What I find so weird is that the nextjs docs don't set any types on the await in their examplesAre you sure that the return type of
getAudit
is correct?
oh wait it's a JS function nvmit is the data I'm using, but I am also very stupid so I may be wrong. Full file:
it will be a TS function once I become better at this TS thing
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
const audit: Audit = await ...
might work too?how would audit: Audit work? Should I copy the props type to a different Audit type?
@Geezer Give a few seconds/minutes to understand your code 🙂
yeah take the audit part and put it in a separate type
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Idk if TS will be happy with that since it's still an assignment of
any
but it might work
If that doesn't work then Geezer's solution of as Audit
would be necessaryTS not happy with audit as it's own thing. Currently chewing through geezers suggestion, allot to take inn
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
fire alarm going, be back in not too long
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Was just a carpenter having a smoke 🙃
Your solution worked @Geezer, thanks!
So I say audit = waiting for something sent as string -> this await returns the data that fits Audit props. still weird how I couldn't use just Props directly, but it probably makes sense somehow
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View