K
Kysely•13mo ago
elitan

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:
export interface Reports {
reportId: Generated<number>;
clientId: number;
[20+ more rows]
export interface Reports {
reportId: Generated<number>;
clientId: number;
[20+ more rows]
Meaning, the clientId do exists on the reports table. What am I doing wrong and how should I debug this issue?
No description
Solution:
ah, seems like LID/RID was a string but should be a number. Hard to debug these error messages.
Jump to solution
8 Replies
Igal (mobile)
Igal (mobile)•13mo ago
Hey 👋 Can you provide a kyse.link?
elitan
elitanOP•13mo ago
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
koskimas
koskimas•13mo ago
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 messages
elitan
elitanOP•13mo ago
ok, 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
elitan
elitan•13mo ago
ah, seems like LID/RID was a string but should be a number. Hard to debug these error messages.
koskimas
koskimas•13mo ago
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.
elitan
elitanOP•13mo ago
Second option does not sound too bad. Good error messages for debugging is such a painkiller.
Want results from more Discord servers?
Add your server