Error with tRPC & Drizzle with numeric data type

Im quite confused on this one. I'm getting an overload error saying the properties don't exist on type and then lists the type with those exact properties. Its not unique to one individual property. Any that I try give me the same error. I've attached screenshots of the trpc function as well as my schema. Plz let me know if you want any more info or have any idea as I'm flabbergasted :/
No description
No description
Solution:
I have a feeling that a numeric data type is a string. So you would use z.string() Please test I may be wrong...
Jump to solution
5 Replies
Neffrey
NeffreyOP7mo ago
Oh. Guess I should add the error. :/ No overload matches this call. Overload 2 of 2, '(values: { userId: string | SQL<unknown> | Placeholder<string, any>; total: string | SQL<unknown> | Placeholder<string, any>; hourly: string | SQL<unknown> | Placeholder<...>; startDate: SQL<...> | ... 1 more ... | Placeholder<...>; endDate: SQL<...> | ... 1 more ... | Placeholder<...>; id?: string | ... 2 more ... | undefined; }[]): PgInsertBase<...>', gave the following error. Object literal may only specify known properties, and 'userId' does not exist in type '{ userId: string | SQL<unknown> | Placeholder<string, any>; total: string | SQL<unknown> | Placeholder<string, any>; hourly: string | SQL<unknown> | Placeholder<string, any>; startDate: SQL<...> | ... 1 more ... | Placeholder<...>; endDate: SQL<...> | ... 1 more ... | Placeholder<...>; id?: string | ... 2 more ... |...'.ts(2769)
peterkyle01
peterkyle017mo ago
You should add the userId to your input schema too
Neffrey
NeffreyOP7mo ago
But I want to get it directly from ctx. Though even changing it to the input schema doesnt fix it :/ After some testing, Its an error with the numeric data type. It works after commenting out my code in both the schema and trpc function. After uncommenting, error returns. Error persists after removing object with precision and scale. So it seems like the data type isnt being handled correctly. Not sure if me, trpc, drizzle... idk Now I believe it to be in the interaction of Zod and Drizzle mixed with number types. Integer, number, decimel, still throws same error even with basic z.number() input checking. Guess I'm saving it as a numerical str for now :/
Solution
Lukem121
Lukem1217mo ago
I have a feeling that a numeric data type is a string. So you would use z.string() Please test I may be wrong
Neffrey
NeffreyOP7mo ago
omg youre right. It is a string! Now a little extra code to validate the string but thats not too bad. Ty!
Want results from more Discord servers?
Add your server