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
Prisma.validator: with clientExtensions enabled, Typescript can no longer compute types #17767
Comments
Thanks for your reproduction. I will take a look now. |
As far as I can tell, this error is just a more general version of what was referenced on #17563. I don't see how it's possible that that issue is fixed if even this one doesn't work. |
const testTableQuery = {
id: true,
task_name: true,
};
const validated = Prisma.validator<Prisma.TestTableSelect>()(testTableQuery) If you hover over That internal change is more correct because So all of this boils down to:
So for you, everything will work once you can narrow types as they should have const testTableQuery = Prisma.validator<Prisma.TestTableSelect>()({
id: true,
task_name: true,
});
const testFunction = async () => {
const taskResult = await prisma.testTable.create({
data: {
task_name: "Testing",
},
select: testTableQuery,
});
console.log(taskResult.id.toString());
} And for us it is to investigate what to do when input is both |
Also, this change does not seem to be influenced by extensions, but by the version. Does that match your understanding too? |
No - my code works fine on version 4.9.0 without the client extensions enabled, as it has on all the prior prisma versions as well. It's only with client extensions enabled that any of this breaks at all. Also, I'm really not sure what you're getting at. As far as I can tell I am using this as documented here. I am literally defining these as "true", not boolean. You can see however VSCode (correctly) indicating that true is in fact a boolean: I'm not saying "boolean" anywhere so I don't see what else I would do differently. I'm also not saying false anywhere (the word is literally not in the codebase). So - exactly what do you mean by narrowing and how exactly would I do that when I'm already using "true"? |
This is for you to be unblocked right now. As I said above, we should not return |
I mean, to me, it goes beyond not being documented to not being logical, ie: a = {x: true, y: true}; I think most people would expect this to be true. |
|
Thank you for taking the time to explain, I really do appreciate it. It took a while but I rooted out all the instances of this in our project and was finally able to get a build out of it. It's probably for the best; it sounds like our use of the validator wasn't having it's intended effect anyway. |
All resolved @jove4015 then? |
Well - we're not blocked anymore, we just updated to use the validator the same exact way and also to use it for every single prisma call, and now we don't have type errors (on version 4.9). I think we're fine just continuing to work that way. So again thank you so much. That being said, I went back to check on the demo repo and I upgraded it to 4.10. It did not seem to fix the problem there - I'm still seeing the same type error after generating and restarting typescript. I'm not sure if that's a big deal - the only thing that's really missing is some info in the documentation to indicate that the validator - used in a very specific way - or a narrowly declared type - is required when working with client extensions. Most examples don't use the validator, and you either have to use it or define all your queries inline (which at least for our project would be pretty impractical). In the absence of any other info to the contrary, I would otherwise expect that if you can write this:
you should also be able to express the same via the substitution property of equality:
It's just not obvious that these limitations apply. |
I am running into what I think is a related issue on Prisma 4.10.1. I have a deeply nested include/select:
The "site", "task", "assignee", "order", and "source" are all relations into other tables. The order id and name are fields in the Order table. Introspecting the PrismaFax type gives the expected |
Recording this for use by others: Replacing |
Bug description
On the most basic schema, when Client Extensions are enabled, Typescript is no longer able to properly generate types for query results. One does not need to implement any specific client extension - in fact, one doesn't have to use them at all. Simply enabling Client Extensions completely renders any project uncompilable.
Please see the sample repository to reproduce.
How to reproduce
Please see the sample repository with full reproduction instructions here: https://github.com/jove4015/special-umbrella.
In the repo, you will see a very simple application that inserts one record into a basic table with all scalar fields and no relationships. It runs correctly without client extensions enabled, but fails the second client extensions are turned on.
Expected behavior
With client extensions enabled, Prisma should still be able to resolve types properly and compile. Client Extensions should be usable.
Prisma information
Schema:
Prisma version 4.9.0
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: