question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Updateable<T> allow undefined?

See original GitHub issue

Why 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: image

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
koskimascommented, Sep 23, 2022

undefined and missing property are both allowed unless exactOptionalPropertyTypes 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.

1reaction
bestickleycommented, Sep 25, 2022

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>.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found