I noticed prisma didn't generate all the different...
# orm-help
n
I noticed prisma didn't generate all the different types for my models after the first Model I created (I am using JavaScript). The first Model I created was called User, and when I saw the intellisense on
prisma.user
I was impressed, I have gone on to create 9 more models after this and the only thing it suggests is the other model names
await prisma.modelname
, after this there's no types again once you start using
create
,
findMany
..e.t.c When I hover my mouse over , it just shows type
any
Can someone please help me out on how to fix this, it prevents me from making some errors as I know what method and properties are safe to use
r
@Nathaniel Babalola đź‘‹ Try restarting your editor after running
prisma generate
.
n
Hi @Ryan , done that not working....we can see the
types
on the first two pics are for
create
and
findUnique
on model user.
while on these customerSupport and flightBooking model
create
is showing type any
r
prisma
is being imported correctly here?
n
yes it is @Ryan
r
No idea then unfortunately. If you could share your project then it would be great so I can check what’s causing this.
Also it’s recommended to create a single instance of
PrismaClient
and import it in all your controllers. Don’t create a new instance for each controller.
n
ooh okay @Ryan, I looked at the index.d.ts file generated. comparing two models (btw I don't know much about Typescript), but looking at the get user() function has a
UserDelegate
of type interface of
Prisma.UserDelegate<GlobalRejectSettings>
while for get passport() it's
PassportDelegate
has a type of
any
But apparently both intefaces exist in the same
index.d.ts
, the get user() function can get the
UserDelegate
interface, but it just seems like the get passport() function can't access
PassportDelegate
interface. And this is the case for the other models except
user
model. @Ryan
r
Could you share your model with me?
n
okay sure, @Ryan this is it
Hi @Ryan , anything yet ?
@Ryan apparently only the
user
model was created in the
Prisma
namespace in
index.d.ts
. I removed the
Prisma
from
Prisma.PaymentDelegate<GlobalReject>
to become just
Payment<GlobalReject>
and the types have now started working. look at the second picture. So why is Prisma creating the types for these models outside the Prisma namespace which is not available to their
get()
methods ? Seems these modifications I made will be overwritten when I run
prisma generate
again
r
I checked and cannot reproduce unfortunately. I tried this on the latest version of
prisma
and
@prisma/client
. The
customerSupport
create works fine.
Could you try this on a sample project? Just copy your
schema.prisma
over and run
prisma generate
.
n
hi @Ryan, I have done it and it's still the same thing. Only model
user
has intellisense types. The same issue with the
index.d.ts
is still happening. Take a look at the following pictures.
PassportDelegate
is showing type any. meaning it's still outside the
Prisma
namespace
r
No idea then unfortunately. I have checked it on a new project and I get all the types. Let me share the sample project with you.
n
@Ryan hmm, okay pls do
r
Working example for
customerSupport
with types. It’s present in the
seed.ts
file.
n
Okay, thanks . @Ryan In the
schema.prisma
file with the models , I decided to move the
user
model to the bottom. Meaning the
Passport
model was first, apparently it now became only the
PassportDelegate
to be in the prisma namespace. Lol this is so confusing, it's only including the first Model in the schema file in the
Prisma
namespace.
r
Changing the location of the User model makes no difference:
n
@Ryan apparently it did in mine,
UserDelegate
is now type
any
and
PassPortDelegate
is now an
interface
r
Try checking the versions of Prisma and see if there’s any mismatch. Otherwise you would need to create an issue here so that we can check. Does the same thing happen in the project that I sent you?
n
@Ryan yes the same thing still happens with the project you sent.
r
Best open an issue then. Might be a Windows problem.