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

PrismaSelect - better typescript support #260

Open
skworden opened this issue May 13, 2022 · 0 comments
Open

PrismaSelect - better typescript support #260

skworden opened this issue May 13, 2022 · 0 comments

Comments

@skworden
Copy link

skworden commented May 13, 2022

I'd like a way to pass our own defaultOptions type for PrismaSelect defaultOptions.

The select function is any, and the object keys are generic string.

For reference, here's an example that is fully typed for nexus autogenerated types. Nexus autogenerated types are dynamic nested objects.

import { NexusGenFieldTypes } from "/my/nexus-types.generated";

// Can be the current default option
type AllowedNexusTypes = Partial<
  Omit<NexusGenFieldTypes, "Mutation" | "Query">
>;

type DefaultFields<T = AllowedNexusTypes> = Required<{
  [K in keyof T]:
    | Partial<{ [P in keyof Required<T>[K]]: boolean }>
    | ((select: Required<T>[K]) => Record<string, boolean>);
}>;


const defaultFields: TDefaultFields = {
  Category: { id: true }, // key and options are typed
  Page: (select) => ({ // key, options, and select are typed
    id: true,
    categoryId: !!select.category,
  }),
  Tag: { id: true },
}
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

No branches or pull requests

1 participant