Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the type of id on type BaseItem, to be type unknown, not string #9054

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dcousens
Copy link
Member

@dcousens dcousens commented Mar 6, 2024

This pull request updates the type of id on type BaseItem to be of type unknown instead of string. This helps reduce a number of type errors where string | number | null is possible, but only string was accepted by the BaseItem.

This is not strictly related to #8846, but will likely be required as part of fixing that problem in any event.

Copy link

codesandbox-ci bot commented Mar 6, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 7956a1b:

Sandbox Source
@keystone-6/sandbox Configuration

@@ -442,7 +442,7 @@ export async function checkUniqueItemExists (
throw missingItem(operation, uniqueInput)
}

return { id: item.id.toString() }
return { id: item.id }
Copy link
Member

Choose a reason for hiding this comment

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

Removing this toString will break if you have a bigint since a bigint wouldn't be accepted by the ID type

@@ -14,7 +14,7 @@ export type BaseListTypeInfo<Session = any> = {
create: GraphQLInput
update: GraphQLInput
where: GraphQLInput
uniqueWhere: { readonly id?: string | number | null } & GraphQLInput
uniqueWhere: { readonly id?: unknown } & GraphQLInput
Copy link
Member

@emmatown emmatown Mar 6, 2024

Choose a reason for hiding this comment

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

string | number | null covers all that the input ID GraphQL type could be, what does widening this help?

data: { listKey, itemId: item.id.toString() },
data: {
listKey,
itemId: item.id
Copy link
Member

Choose a reason for hiding this comment

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

If you had a bigint id, this would fail since JSON.stringify with a bigint throws

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants