as type error

If no relationships are configured in the model, no type error occurs, but if a relationship model is defined in the model, a type error occurs
async create<T extends Prisma.TokenRecordCreateArgs>(args: T) {
return this.prisma.tokenRecord.create(args) as Promise<Prisma.TokenRecordGetPayload<T>>;
}
async create<T extends Prisma.TokenRecordCreateArgs>(args: T) {
return this.prisma.tokenRecord.create(args) as Promise<Prisma.TokenRecordGetPayload<T>>;
}
TS2352: Conversion of type
Prisma__TokenRecordClient<{ id: number; subject: 'NONE'; accessToken: string; ip: string; isExpiration: boolean; createdAt: Date; updatedAt: Date; userId: number | null; }, never, DefaultArgs, PrismaClientOptions>
to type
Promise<GetFindResult<$TokenRecordPayload<DefaultArgs>, T, {}>>
may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to unknown first.
Types of property then are incompatible.
Type '<TResult1 = { id: number; subject: "NONE"; accessToken: string; ip: string; isExpiration: boolean; createdAt: Date; updatedAt: Date; userId: number | null; }, TResult2 = never>(onfulfilled?: ((value: { id: number; subject: "NONE"; ... 5 more ...; userId: number | null; }) => TResult1 | PromiseLike<...>) | null | und...' is not comparable to type '<TResult1 = GetFindResult<$TokenRecordPayload<DefaultArgs>, T, {}>, TResult2 = never>(onfulfilled?: ((value: GetFindResult<$TokenRecordPayload<DefaultArgs>, T, {}>) => TResult1 | PromiseLike<...>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | ... 1 more ... | undefined) => Promise...'.
Types of parameters onfulfilled and onfulfilled are incompatible.
Types of parameters value and value are incompatible.
Type
{ id: number; subject: 'NONE'; accessToken: string; ip: string; isExpiration: boolean; createdAt: Date; updatedAt: Date; userId: number | null; }
is not comparable to type
GetFindResult<$TokenRecordPayload<DefaultArgs>, T, {}>
TS2352: Conversion of type
Prisma__TokenRecordClient<{ id: number; subject: 'NONE'; accessToken: string; ip: string; isExpiration: boolean; createdAt: Date; updatedAt: Date; userId: number | null; }, never, DefaultArgs, PrismaClientOptions>
to type
Promise<GetFindResult<$TokenRecordPayload<DefaultArgs>, T, {}>>
may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to unknown first.
Types of property then are incompatible.
Type '<TResult1 = { id: number; subject: "NONE"; accessToken: string; ip: string; isExpiration: boolean; createdAt: Date; updatedAt: Date; userId: number | null; }, TResult2 = never>(onfulfilled?: ((value: { id: number; subject: "NONE"; ... 5 more ...; userId: number | null; }) => TResult1 | PromiseLike<...>) | null | und...' is not comparable to type '<TResult1 = GetFindResult<$TokenRecordPayload<DefaultArgs>, T, {}>, TResult2 = never>(onfulfilled?: ((value: GetFindResult<$TokenRecordPayload<DefaultArgs>, T, {}>) => TResult1 | PromiseLike<...>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | ... 1 more ... | undefined) => Promise...'.
Types of parameters onfulfilled and onfulfilled are incompatible.
Types of parameters value and value are incompatible.
Type
{ id: number; subject: 'NONE'; accessToken: string; ip: string; isExpiration: boolean; createdAt: Date; updatedAt: Date; userId: number | null; }
is not comparable to type
GetFindResult<$TokenRecordPayload<DefaultArgs>, T, {}>
4 Replies
Prisma AI Help
Greetings, curious mind! I'm the Prisma AI Help Bot. Want to chat with a human team member (ETA: TBD)? Or skip the wait and get my best guess right now? The speed of automation awaits you.
Nurul
Nurul2w ago
Hey 👋 Can you please provide a small reproduction?
진양철
진양철OP2w ago
hi I'm organizing a class that can be controlled on a per-model basis. When I run a function that encapsulates a prisma externally, I expect the type to be inferred based on the external options.
model TokenRecord {
id Int @id @default(autoincrement())
subject TOKEN_RECORD_SUBJECT
accessToken String @db.VarChar()
ip String @db.VarChar()
isExpiration Boolean @default(false) @map("is_expiration")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3)
}
model TokenRecord {
id Int @id @default(autoincrement())
subject TOKEN_RECORD_SUBJECT
accessToken String @db.VarChar()
ip String @db.VarChar()
isExpiration Boolean @default(false) @map("is_expiration")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3)
}
If it is not associated with another model, as above, no error will occur. However, if you connect with a different model, you get the same error.
model TokenRecord {
id Int @id @default(autoincrement())
subject TOKEN_RECORD_SUBJECT
accessToken String @db.VarChar()
ip String @db.VarChar()
isExpiration Boolean @default(false) @map("is_expiration")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3)
users User[] <- here.
}
model TokenRecord {
id Int @id @default(autoincrement())
subject TOKEN_RECORD_SUBJECT
accessToken String @db.VarChar()
ip String @db.VarChar()
isExpiration Boolean @default(false) @map("is_expiration")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3)
users User[] <- here.
}
async create<T extends Prisma.TokenRecordCreateArgs>(args: T) {
return this.prisma.tokenRecord.create(args) as Promise<Prisma.TokenRecordGetPayload<T>>;
}
async create<T extends Prisma.TokenRecordCreateArgs>(args: T) {
return this.prisma.tokenRecord.create(args) as Promise<Prisma.TokenRecordGetPayload<T>>;
}
My temporary workaround was to abandon no await return. I used await return and excluded the Promise type and it worked, but I'd like to use no await return because I'd like to wait on the calling side of the function for performance reasons.
async create<T extends Prisma.TokenRecordCreateArgs>(args: T) {
return (await this.prisma.tokenRecord.create(args)) as Prisma.TokenRecordGetPayload<T>;
}
async create<T extends Prisma.TokenRecordCreateArgs>(args: T) {
return (await this.prisma.tokenRecord.create(args)) as Prisma.TokenRecordGetPayload<T>;
}
Nurul
Nurul2w ago
The error occurs because the type returned by prisma.tokenRecord.create() doesn't exactly match the type you're asserting with Promise<Prisma.TokenRecordGetPayload<T>> This mismatch becomes more apparent when relationships are involved because the returned type includes additional properties related to the relationships. If you really want to return without awaiting, one workaround could be to cast the result first to unknown and then to the desired Promise type:
async create<T extends Prisma.TokenRecordCreateArgs>(args: T) {
return this.prisma.tokenRecord.create(args) as unknown as Promise<Prisma.TokenRecordGetPayload<T>>;
}
async create<T extends Prisma.TokenRecordCreateArgs>(args: T) {
return this.prisma.tokenRecord.create(args) as unknown as Promise<Prisma.TokenRecordGetPayload<T>>;
}
However, this double cast essentially bypasses TypeScript’s type checking for that conversion and may hide genuine mismatches between the expected payload type and what Prisma returns. It’s generally better to await the result to ensure type correctness, which you are doing

Did you find this page helpful?