what I’m trying to do is something like: ```type E...
# orm-help
b
what I’m trying to do is something like:
Copy code
type EntityKeys = "user" | "project" | "projectType";
type PrismaDelegates = Pick<typeof db, EntityKeys>;
type Entity = {
  [Key in EntityKeys]: PrismaDelegates[Key];
}[EntityKeys];

const SLUG_TO_ENTITY = {
  users: "user",
  projects: "project",
  "project-types": "projectType"
};


// `db` is a reference to an instance of the PrismaClient
const model: Entity = db[SLUG_TO_ENTITY[entity as keyof typeof SLUG_TO_ENTITY] as EntityKeys];
Then intellisense shows correctly that
model
has
count
and
findMany
but because their signatures are not compatible with each other I get a typing error. Any ideas?
i
https://www.prisma.io/graphql It almost sounds like you're in a situation that the graphql integration could solve? What is the motivation for trying to lock into this pattern?
h
You could try define
SLUG_TO_ENTITY
with
as const
and then you probably don’t need that casting that is really not safe. It should infer that model type