Skip to content

Conversation

@nyoung697
Copy link
Contributor

Generate the correct types for a record, instead of just returning any.

The type RecordKeyValidatorJSON isn't exported from the convex package, but if it were to be exported, the generateRecordKeyType function can be updated.

@jordanhunt22 jordanhunt22 self-requested a review February 11, 2025 23:45
Copy link
Contributor

@jordanhunt22 jordanhunt22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nyoung697 for this contribution!

I'm going to update the convex package to export the RecordKeyValidatorJSON and RecordValueValidatorJSON objects. That way, we can do this correctly. Can you please ping me in 1-2 weeks if I don't circle back?

return 'any'
case 'record': {
const keyType = generateRecordKeyType(argsJson.keys)
const valueType = generateArgsType(argsJson.values.fieldType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this value type is also restricted because it can't be optional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jordan! What do you mean by this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified it to check if the field is optional and it will add undefined. Is this the correct way of handling this?

case 'record': { const keyType = generateRecordKeyType(argsJson.keys); const valueType = generateArgsType(argsJson.values.fieldType); const isOptional = argsJson.values.optional ? " | undefined" : ""; return `Record<${keyType}, ${valueType}${isOptional}>`; } 
convex-copybara bot pushed a commit to get-convex/convex-backend that referenced this pull request Feb 12, 2025
Exports `RecordKeyValidatorJSON` and `RecordValueValidatorJSON`, so we can properly support [this](get-convex/convex-helpers#447) change. GitOrigin-RevId: 933eadedd710b068ba5106578ff0701bee7bd5e1
convex-copybara bot pushed a commit to get-convex/convex-js that referenced this pull request Feb 12, 2025
Exports `RecordKeyValidatorJSON` and `RecordValueValidatorJSON`, so we can properly support [this](get-convex/convex-helpers#447) change. GitOrigin-RevId: 933eadedd710b068ba5106578ff0701bee7bd5e1
Copy link
Contributor

@jordanhunt22 jordanhunt22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I exported the types from convex-js to make this a bit easier. The pr I made is here

/**
* Generates a TypeScript-compatible key type for a record.
*
* The keys should actually be RecordKeyValidatorJSON, but this isn't exported from validators.ts in convex.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please update this to use the types I exported here? Please also do the same with the values.

case "record": {
const keyType = generateRecordKeyType(argsJson.keys);
const valueType = generateArgsType(argsJson.values.fieldType);
const isOptional = argsJson.values.optional ? " | undefined" : "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

values should never be optional

@ianmacartney ianmacartney self-requested a review March 6, 2025 22:33
Copy link
Collaborator

@ianmacartney ianmacartney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see jordan's feedback

@nyoung697
Copy link
Contributor Author

I added the RecordKeyValidatorJSON type. I don't know what you want me to do with the value type.

Copy link
Contributor

@jordanhunt22 jordanhunt22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good. Thanks for contributing! Can you confirm that we can modify, copy, and redistribute this contribution by adding a thumbs up to this message?

Once that's done, we can go ahead and get this merged in.

@jordanhunt22 jordanhunt22 merged commit f5bc1e7 into get-convex:main Mar 25, 2025
@ianmacartney
Copy link
Collaborator

It's live in convex-helpers@0.1.76 - thanks for your patience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants