ts error help
Error :
'campaign' is referenced directly or indirectly in its own type annotation.
In my utils.ts if i add one more export function then this error is being given by ts but if there is only one export function then there is no ts error11 Replies
Uploaded the utils.ts for more help
checkIfCampaignIsInPast()
is referencing your getCampaignWithId
query type in its signature, that's a circular reference.
(Assuming getCampaignWithId
is calling checkIfCampaignIsInPast()
)
If it isn't calling it directly, you'll have to look at the things it does call or reference, the things they call or reference, etc. to find the circular reference.How to check this, I am not great with ts
also why its only happening when adding one more function to file if theres only one function then ts err is not poping up
So the version of the util file you shared doesn't error?
Until you add another function?
yes
Can you share a version of the util file that errors?
this file if you remove the second function then there is no ts err
Ah I was on my phone and didn't even see the second function lol
checking now
Is that second function being called anywhere
yes
its being called
In general, adding more explicit type annotations for return values will help (e.g. looks like the first thing returns a boolean, so add a
: boolean
). I'd try adding annotations to these two helpers and also getCampaignWithId
The big red flag to me is using the return type of
api.campaign.getCampaignWithId
in the signature of that first utility function. Can't say for sure, but I bet if you built that type without referencing the query function you'll get rid of the error.
Also note, just to help it not feel so mysterious, this is very unlikely to be due to having two functions instead of one in the util file. If you add an empty function, you're unlikely to get the error. Another good starting point for troubleshooting is commenting out the body of that second function and just returning any date so your types are happy, then see if you still get the type error.