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
$extends
TS error: "Inferred type of this node exceeds the maximum length the compiler will serialize" with "declaration": true
in tsconfig
#16536
Comments
Can you confirm this is a regression from |
Um no, I'm just trying this feature for the first time as it was just released in version 4.7.0 |
I confirm a regression, I have this too on just a new PrismaClient() |
Hey, @mshd we need the schema to be able to reproduce the problem. So far, I have been able to successfully generate the client using the following schema: // This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
previewFeatures = ["clientExtensions"]
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model Image {
id Int @id @default(autoincrement())
imageUrl String? @unique
} And to extend it to compute the image URL from the id: import { PrismaClient } from '@prisma/client'
export const prismaClient = new PrismaClient().$extends({
result: {
image: {
imageUrl: {
needs: { id: true },
compute: ({ id }) => {
return `https://storage.googleapis.com/entitree-images/${id}.jpg`;
},
}
}
}
})
async function main() {
await prismaClient.image.create({ data: {} })
const image = await prismaClient.image.findFirst()
console.log(image?.imageUrl)
}
main()
.then(async () => {
await prismaClient.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prismaClient.$disconnect()
process.exit(1)
}) Here's a zip ball with the reproduction: repro.zip |
I also tried using This schema, and both generation and execution against postgres worked correctly too. |
Hi @mshd and thank you for your report! This error is related to failure to emit declarations — notice that despite the error, if you hover the mouse over the variable in your editor, you can still see that TypeScript infers a type. Adding "compilerOptions": {
"declaration": false
} to |
$extends
TS error: "Inferred type of this node exceeds the maximum length the compiler will serialize" when emitting declarations
$extends
TS error: "Inferred type of this node exceeds the maximum length the compiler will serialize" when emitting declarations$extends
TS error: "Inferred type of this node exceeds the maximum length the compiler will serialize" with "declaration": true
in tsconfig
@yovanoc I can't reproduce this with just |
Hey @mshd I am not able to reproduce this exact same error. However, after taking a look at the generated types, I found that there is a clash with our
|
Any additional information you can give us @adamhamlin to reproduce and understand what is going on? We thought this was fixed in December :/ |
@janpio I kind of alluded to it, but my suspicion is that the use of |
@adamhamlin You are correct, or at least from my first investigation performance issues are arising with how we deal with intersections, which are inefficient, on $allModels. Currently, I consider your issue to be 100% related to what's been reported at #19999, for some it will be a length serialization error, for others it will be memory exhaustion (I've seen both while investigating the issue). |
At the moment, my minimal reproduction is the following. Could you confirm this also fails on your end? const prisma = new PrismaClient().$extends({
model: {
$allModels: {
async paginate<T, A>(
this: T, args: Prisma.Exact<A, Prisma.Args<T, "findMany">>
) {
return {} as Prisma.Result<T, A, "findMany">
}
}
}
}) |
@millsp yes, confirming the same issue using your example |
Hey @adamhamlin, we have a branch/fix for you to try over here. If you have some time, I'd love if you could give it a try and let me know if that helped. Thanks. |
@millsp interestingly the new branch resolved the issue when using your minimal/toy example, but it did not when using my actual extension. I'll just go ahead and post my extension here in case that helps (it's more or less copied/adapted from this). Also, no change if using const createManyAndReturnWithIdsExtension = Prisma.defineExtension((client) => {
return client.$extends({
name: 'createManyAndReturnWithIds',
model: {
$allModels: {
/**
* Bulk insert the specified inputs and return with ID information
*/
async createManyAndReturnWithIds<T, A>(
this: T,
args: Prisma.Exact<A, Omit<Prisma.Args<T, 'createMany'>, 'skipDuplicates'>>,
): Promise<Array<Prisma.Result<T, A, 'create'> & { id: number }>> {
const thisCast = this as any;
const argsCast = args as any;
argsCast.data.forEach((record) => {
if (record.id) {
throw new Error('Cannot provide explicit IDs when using createManyAndReturnWithIds');
}
});
const ctx = Prisma.getExtensionContext(this);
const tableName = _.kebabCase(ctx.name);
const numRecords = argsCast.data.length;
const ids = (
await client.$queryRaw<Array<{ id: bigint }>>`
SELECT nextval(pg_get_serial_sequence(${tableName}, 'id')) AS id
FROM generate_series(1, ${numRecords})
`
).map((row) => Number(row.id));
const newRecords = argsCast.data.map((record, idx) => {
return {
id: ids[idx],
...record,
};
});
await thisCast.createMany({
...argsCast,
data: newRecords,
});
return newRecords;
},
},
},
});
}); |
Thanks for sharing, I'll take a look. |
Hello, unfortunately we have a similar problem. Prisma client $extension with Thanks for your effort and best regards |
Thanks for your reproduction @adamhamlin, I can confirm that it will be fixed. |
The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.
This error also showed up in another project.
Source file. To reproduce, check out main, and upgrade to Prisma 4.7
The text was updated successfully, but these errors were encountered: