opral / lix-sdk

1 stars 0 forks source link

(lix sdk) use `null | T` instead of `undefined | T` #55

Open samuelstroschein opened 2 weeks ago

samuelstroschein commented 2 weeks ago

Context

https://github.com/kysely-org/kysely/issues/27#issuecomment-986076120

Proposal

Define database schema types as null | T instead of undefined | T to avoid bugs.

samuelstroschein commented 4 days ago

Using T | null leads to breaking changes for newly added (optional) columns.

Here is a reproduction https://www.typescriptlang.org/play/?#code/C4TwDgpgBAcgrgGwQQwEYIgFTRqBeKAbwCgBIAE2WGQC4oBBAJ0eRACE4AzTiRgbjIBbCNUrU6AJQgBjAPaNyAHgDOwRgEsAdgHMANFGSaQAPigAfKJsQIBAXwHFQkKAFVN5CJy04sP-ETIxWgZmVg5uXgFSYVEqZAB+SRl5JVUNHX1DEzsHOU1VKGp0CHgkHzpSlGLsYv8SCji6TQgAdxCWdi4eRgAKAAYASl1ie2JiPIKijDcPL01y13dPb2q-Anqgptb2sK7efqGR3Nl82QwAOgRZbR6pkusffTuZ5fnigaA.

Adding a column to a table and marking it with null, leads to breaking changes everywhere the type SomeTable or Selectable<SomeTable> is used.

type SomeTable = {
    data: ArrayBuffer;
+   metadata: Record<string, any> | null;
}; 

Additional context