Object literal may only specify known properties, and photo does not exist in type
My query is
Near photo in select I get the type error
My IDE is webstorm 2023.3.4
The result of this query is successful (screenshot in attach)
How to deal with this type error?
11 Replies
@andreas_444 have you included photo in the relations for the avatar table?
@Aaroned phid in avatar isnt fk. And I prefer not to use fk in this case
can't you just do
photo: getTableColumns(photos)
? should be easier on the type-checker
also is this reproducible in typescript playground? you dont have to post it here - just check yourself if the error is still there in other environments. TS playground can import stuff from npm packages out of the box so you would just need to paste in a bit of code of your schema declaration and drizzleClient - shouldn't be too hard.
I'm asking cause I've had colleagues encounter weird behavior with TS in WS so could be an issue on their end
this doesn't seem to be a relation query - just a regular one so I don't think that matters here@andreas_444 @Huge Letters sorry, yes I just realised this is not a relation query (I was mislead by the hierarchical structure)
If you look at the definition of
select
you can see if accepts a SelectedFields
object, which doesn't allow for nested object hierarchy.
Either you can define the query like this:
Or define the relation and use a relation query with a full hierarchical data object result.yup, tested myself - you're correct, it only allows 1-level deep nesting basically
I`ve already tried like this
The same issues
In zed this issue appears, too
@Aaroned Does the team have any plans to improve the typification for hierarchical queries?
Not quite. When typification shows error, the query returns the correct result, regardless of the hierarchy level
in that case I think you're correct and that's an error with type definition
you could file an issue on github but I don't know if this is gonna be a priority - you could fix the select easily like this but it won't infer result type correctly and fixing that seems to be much more complicated, at least at the first glance for me
Already created the bug report https://github.com/drizzle-team/drizzle-orm/issues/2050
GitHub
[BUG]: Nested object in select query · Issue #2050 · drizzle-team/d...
What version of drizzle-orm are you using? 0.29.3 What version of drizzle-kit are you using? 0.20.14 Describe the Bug My code is const feedbacks = await drizzleClient .select({ ...getTableColumns(f...
FYI I just noticed this comment here https://orm.drizzle.team/docs/rqb#foreign-keys
What this means is relations and foreign keys can be used together, but they are not dependent on each other. You can define relations without using foreign keys (and vice versa), which allows them to be used with databases that do not support foreign keys.
In my case, I don’t use foreign keys to simplify data mutation in the database. Foreign keys are needed for data consistency. I don`t really need it
That's fair enough. But if you want you are welcome to define Drizzle ORM level relations (and hence use relation queries) without having to define database level foreign keys 😊