jeff
jeff10mo ago

Surely a bug (with TypeScript fanciness) ?

See screenshots. The only thing I am changing is the type of quotes (double quotes to back ticks, for variable interpolation) in line 156. This breaks anterior bits of code... o.O It complains about request implicitly being of type any, but this error message persists, even after I add explicit type annotations. Also, there is no circular reference (that I can see). What is this dark evilness?
No description
No description
21 Replies
erquhart
erquhart10mo ago
The circular reference is happening because the return value of a convex function (request) is in the return value. Assign request.status to its own variable and use that in your interpolation to clear up the error.
jeff
jeffOP10mo ago
const requestStatus = request.status;
const requestStatus = request.status;
-->
'requestStatus' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)
'requestStatus' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)
okay an explicit type annotation fixed this thanks for your help ❤️ I can unequivocally say, though, that I do not remotely understand this. the return value of one function is returned in the encapsulating function ... that's just standard procedural programming, no? XD
erquhart
erquhart10mo ago
It is, but Convex generates types for these functions, and directly referencing the return value of one function from inside of another creates a circular reference. Type annotation definitely works, but you can go back to letting the return value be inferred if you just don't directly reference the other function's return value, which could look like:
const requestStatus = request.status
return { message: `status=${requestStatus}` }
const requestStatus = request.status
return { message: `status=${requestStatus}` }
jeff
jeffOP10mo ago
that's exactl;y what I did, before the explicit type annotation
jeff
jeffOP10mo ago
No description
jeff
jeffOP10mo ago
convex/payment.ts:155:15 - error TS7022: 'requestStatus' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

155 const requestStatus = request.status;
~~~~~~~~~~~~~
convex/payment.ts:155:15 - error TS7022: 'requestStatus' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

155 const requestStatus = request.status;
~~~~~~~~~~~~~
erquhart
erquhart10mo ago
what's the error above it from line 146
jeff
jeffOP10mo ago
here's all 3:
convex/payment.ts:127:14 - error TS7022: 'verifyPayment' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

127 export const verifyPayment = action({
~~~~~~~~~~~~~
convex/payment.ts:146:27 - error TS7022: 'request' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

146 const {paymentId, request}: {paymentId: Id<"payments">; request: Doc<"requests">} = await ctx.runQuery(
~~~~~~~

convex/payment.ts:155:15 - error TS7022: 'requestStatus' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

155 const requestStatus = request.status;
~~~~~~~~~~~~~

Found 3 errors in the same file, starting at: convex/payment.ts:127
convex/payment.ts:127:14 - error TS7022: 'verifyPayment' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

127 export const verifyPayment = action({
~~~~~~~~~~~~~
convex/payment.ts:146:27 - error TS7022: 'request' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

146 const {paymentId, request}: {paymentId: Id<"payments">; request: Doc<"requests">} = await ctx.runQuery(
~~~~~~~

convex/payment.ts:155:15 - error TS7022: 'requestStatus' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

155 const requestStatus = request.status;
~~~~~~~~~~~~~

Found 3 errors in the same file, starting at: convex/payment.ts:127
erquhart
erquhart10mo ago
I see paymentId on that line seems to be not creating an error - what happens if you don't destructure the return value of ctx.runQuery()? Can you try assigning that to a variable and seeing if the type is correct?
jeff
jeffOP10mo ago
as in const both = runQuery(... and then destructuring both?
erquhart
erquhart10mo ago
yes
jeff
jeffOP10mo ago
(I am new to both JS and TS) ok 2 mins
erquhart
erquhart10mo ago
but mostly interested in whether both is typed in this scenario If you need to just move on since you have a working solution, feel free to do so! I'm interested in troubleshooting it if you have the time.
jeff
jeffOP10mo ago
const paymentIdAndRequest = await ctx.runQuery(internal.payment_utils.getPaymentIdAndRequest, {...args});
const {paymentId, request} = paymentIdAndRequest;
const paymentIdAndRequest = await ctx.runQuery(internal.payment_utils.getPaymentIdAndRequest, {...args});
const {paymentId, request} = paymentIdAndRequest;
still errors
convex/payment.ts:127:14 - error TS7022: 'verifyPayment' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

127 export const verifyPayment = action({
~~~~~~~~~~~~~
convex/payment.ts:146:15 - error TS7022: 'paymentIdAndRequest' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

146 const paymentIdAndRequest = await ctx.runQuery(internal.payment_utils.getPaymentIdAndRequest, {...args});
~~~~~~~~~~~~~~~~~~~

convex/payment.ts:147:27 - error TS7022: 'request' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

147 const {paymentId, request} = paymentIdAndRequest;
~~~~~~~

convex/payment.ts:153:15 - error TS7022: 'requestStatus' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

153 const requestStatus = request.status;
~~~~~~~~~~~~~

Found 4 errors in the same file, starting at: convex/payment.ts:127
convex/payment.ts:127:14 - error TS7022: 'verifyPayment' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

127 export const verifyPayment = action({
~~~~~~~~~~~~~
convex/payment.ts:146:15 - error TS7022: 'paymentIdAndRequest' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

146 const paymentIdAndRequest = await ctx.runQuery(internal.payment_utils.getPaymentIdAndRequest, {...args});
~~~~~~~~~~~~~~~~~~~

convex/payment.ts:147:27 - error TS7022: 'request' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

147 const {paymentId, request} = paymentIdAndRequest;
~~~~~~~

convex/payment.ts:153:15 - error TS7022: 'requestStatus' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

153 const requestStatus = request.status;
~~~~~~~~~~~~~

Found 4 errors in the same file, starting at: convex/payment.ts:127
I, unfortunately, am also a nerd who needs to get to the bottom of this so I can sleep tonight 😛 (also happy to have a brief call, capped at max 30' though, if you wanna do some live debugging) screenshare etc.
erquhart
erquhart10mo ago
Weird, I've definitely seen this resolved by not directly referencing the return value of the other function I'm up for that, one sec
jeff
jeffOP10mo ago
similarly, lemme get a glass of water 1 min kk ready do we need to become friends? 😄
erquhart
erquhart10mo ago
I know discord has calling and screen sharing
jeff
jeffOP10mo ago
yeah, but do we need to become discord friends ios what I meant
erquhart
erquhart10mo ago
sent a request For posterity: this seems to have been due to some tables not being in the schema and schema validation being off temporarily. Still to be confirmed. This ended up being due to directly referencing the return value of a convex function within another convex function, annotating the referenced value was the simplest fix.
jeff
jeffOP10mo ago
Huge thanks to Erquhart for taking the time to figure this out and explain this to me! Once Convex introduces community medals... I have a recommendation! 🎖️
jamwt
jamwt10mo ago
@erquhart is the best

Did you find this page helpful?