Skip to content

Commit

Permalink
Don't assume non nullability on pk
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Rico <[email protected]>
  • Loading branch information
SferaDev committed Sep 26, 2024
1 parent d1222dc commit 65bd0cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 3 additions & 4 deletions packages/client/src/schema/identifiable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const tables = [
]
},
{
name: 'InvalidPrimaryKey',
name: 'NullablePrimaryKey',
primaryKey: ['pk'],
columns: [
{ name: 'pk', type: 'int', notNull: false, unique: true },
Expand Down Expand Up @@ -62,10 +62,9 @@ test('PrimaryKey', () => {
const user3: Type = { pk: 1, xata_version: 1 };
});

test('InvalidPrimaryKey', () => {
type Type = NewIdentifiable<typeof tables>['InvalidPrimaryKey'];
test('NullablePrimaryKey', () => {
type Type = NewIdentifiable<typeof tables>['NullablePrimaryKey'];

// @ts-expect-error
const user: Type = { pk: 1 };
// @ts-expect-error
const user2: Type = { pk: '1' };
Expand Down
4 changes: 3 additions & 1 deletion packages/client/src/schema/identifiable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ type PropertyType<Properties, PropertyName extends PropertyKey> = Properties & {
? {
[K in PropertyName]: InnerType<Type>;
}
: never
: {
[K in PropertyName]: InnerType<Type> | null;
}
: never
: never;

Expand Down

0 comments on commit 65bd0cb

Please sign in to comment.