Object literal may only specify known properties, and 'clientId' does not exist in type 'InsertObjec
I'm getting this issue with an insert statement using Kysely. But I'm not sure what I'm doing wrong.
Here's the Report interface generated via Kysely Codegen:
Meaning, the
clientId
do exists on the reports
table.
What am I doing wrong and how should I debug this issue?![No description](https://cdn.answeroverflow.com/1177534164422119435/CleanShot_2023-11-24_at_09.58.32.png)
Solution:Jump to solution
ah, seems like LID/RID was a string but should be a number. Hard to debug these error messages.
8 Replies
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
https://kyse.link/?p=s&i=xuoahFZZv6ja3sMgwtTo
Is the problem that I need to add all non-nullable and non-undefined fields in my insert?
Updated:
https://kyse.link/?p=s&i=OYPNRzrAU4HrhaXoRwUR
Don't know if that's the issue, but yes, you need to provide a value for all non-nullable fields that are not generated by the DB.
Also
Generated<number | null>
is meaningless. It's basically saying "this value is always generated and can never be null AND it can be null"
If a field can be null, you can just specify it as number | null
even if the DB generates a value for it when you don't provide one.
The error message here is misleading. What happens is that typescript first attempts to match the object you provided to the object overload of the values
method. When that fails (missing fields) it attempts to match it to the array version since arrays are also objects in javascript. That fails once it finds the first property clientId
since array doesn't have the property clientId
.
Then all of this is mangled by typescripts unreadable error messagesok, so, uhm, what do I do? In the last link I do provide a value for all non-nullable fields but I still get the error.
Solution
ah, seems like LID/RID was a string but should be a number. Hard to debug these error messages.
Yeah the error messages are useless 😔 But unfortunately there isn't much we can do without removing functionality or moving the array insert to a separate method.
Second option does not sound too bad. Good error messages for debugging is such a painkiller.
Opened an issue https://github.com/kysely-org/kysely/issues/778