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

Update 063-excluding-fields.mdx #5383

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

Conversation

mubaidr
Copy link

@mubaidr mubaidr commented Oct 17, 2023

Describe this PR

Update exclude function to make it short and compatible with typescript version 4.4+

Changes

Just updated example exclude function definition

What issue does this fix?

Exclude function does not support latest typescript version, gives warnings.

Any other relevant information

N/A

Update exclude function to make it short and compatible with typescript version 4.4+
@vercel
Copy link

vercel bot commented Oct 17, 2023

@mubaidr is attempting to deploy a commit to the Prisma Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Nov 23, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 23, 2023 8:19am

Copy link
Member

@nikolasburk nikolasburk left a comment

Choose a reason for hiding this comment

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

Hey @mubaidr, thanks a lot for this PR 🙏 it looks great 💚

I tested the code and it worked on my machine 🎉

The main concern I have is that it changes the signature of the exclude function and now only allows to exclude a single key, i.e. exclude(user, 'password') instead of multiple keys (passed as an array), e.g. exclude(user, ['id', 'password']) as it's intended.

  • Would you be able to update this and make the exclude function accept an array of keys?
  • Also, can you please make the input obj optional?
  • And finally (since you're on it): This didn't come from your PR but I noticed that the example in main actually doesn't run 🤦

It currently has the following query:

const user = await prisma.user.findUnique({ where: 1 })

but it should be:

const user = await prisma.user.findUnique({
  where: {
    id: 1
  }
})

Thanks for caring about our docs and taking the time to improve them, that's much appreciated!!

Object.entries(user).filter(([key]) => !keys.includes(key))
)
function exclude<T extends object, K extends keyof T>(
obj: T,
Copy link
Member

Choose a reason for hiding this comment

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

can we make this optional?

Suggested change
obj: T,
obj: T | null,

)
function exclude<T extends object, K extends keyof T>(
obj: T,
key: K,
Copy link
Member

Choose a reason for hiding this comment

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

is it possible to keep this as K[]?

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

Successfully merging this pull request may close these issues.

None yet

2 participants