Updateable<T> allow undefined?
See original GitHub issueWhy cannot Updateable<T> allow undefined
?
I’m using zod for input validation. For an update, all properties besides an id should be optional. However, this seems to not allow me to use .set
within Kysely because it does not allow undefined.
Use case:
import { Kysely, KyselyConfig, Updateable } from "kysely";
import { z } from "zod";
interface UserTable {
id: number;
firstName: string | null;
lastName: string | null;
}
interface Database {
user: UserTable;
}
const db = new Kysely<Database>({} as KyselyConfig);
const userSchema = z.object({
id: z.number(),
firstName: z.string().optional(),
lastName: z.string().optional(),
});
const user = userSchema.parse({
id: 1,
firstName: "Ben",
});
// doesn't work
db.updateTable("user").set(user).where("id", "=", 1).execute();
// works
db.updateTable("user")
.set(user as Updateable<UserTable>)
.where("id", "=", 1)
.execute();
Error:
Issue Analytics
- State:
- Created a year ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How to suppress "error TS2533: Object is possibly 'null' or ...
If you know from external means that an expression is not null or undefined , you can use the non-null assertion operator !...
Read more >ParametrizedFieldMapper.Parameter (server 7.9.3 API) - javadoc.io
String name, boolean updateable, T defaultValue, java.util.function.BiFunction<java.lang.String,java.lang. ... Allows the parameter to accept a null value.
Read more >7 Tips to Handle undefined in JavaScript - Dmitri Pavlutin
A detailed article about 'undefined' keyword in JavaScript. 7 tips on how to handle correctly 'undefined' and increase code durability.
Read more >Some way to express a non-null / non-undefined any ... - GitHub
While updating the various .d.ts to have | null and | undefined, I came across some typings that use any but don't allow...
Read more >Updateable allow undefined? - koskimas/kysely - Devscope.io
Why cannot Updateable allow undefined ? I'm using zod for input validation. For an update, all properties besides an id should be optional....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
undefined
and missing property are both allowed unlessexactOptionalPropertyTypes
is true, which treats these two as different cases. Missing/undefined values is a common case, but people using settings this strict is not.Let’s fix this unless we need hacks.
awesome. thanks, @igalklebanov! This seems like a very common use case. I hope your PR gets merged, but if it cannot maybe Kysely could export a helper type like
type NullableColumn<T> = ColumnType<T | null, T | undefined | null, T | undefined | null>
.