Skip to content

Commit

Permalink
Remove from object shape keys with value never (#1051)
Browse files Browse the repository at this point in the history
* Remove from object shape keys with value never

* Fix failing test & add 2 more tests
  • Loading branch information
diksipav authored Jul 9, 2024
1 parent 2a9bec4 commit f6382a5
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions integration-tests/lts/dbschema/default.esdl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module default {
constraint exclusive;
};
property height -> decimal;
property isAdult -> bool;
}

type Villain extending Person {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE MIGRATION m1wb2dgjeppqex272zwvqnsdfzdvvppub4iwa5vaxu3xxigyjlruka
ONTO m1rjlewu5fimvn4lf4xguullcbvlttuxmtxyl4yz4dmsbyw5shva7a
{
ALTER TYPE default::Person {
CREATE PROPERTY isAdult: std::bool;
};
};
1 change: 1 addition & 0 deletions integration-tests/lts/interfaces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface BaseObject {
export interface test_Person extends BaseObject {
name: string;
height?: string | null;
isAdult?: boolean | null;
}
export interface test_Movie extends BaseObject {
characters: test_Person[];
Expand Down
1 change: 1 addition & 0 deletions integration-tests/lts/objectTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ describe("object types", () => {
id: true,
name: true,
height: true,
isAdult: true,
secret_identity: true,
number_of_movies: true,
});
Expand Down
37 changes: 36 additions & 1 deletion integration-tests/lts/select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ describe("select", () => {
id: string;
secret_identity: string | null;
nemesis: { id: string; computable: 1234 } | null;
computable: never;
}[]
>
>(true);
Expand Down Expand Up @@ -336,6 +335,7 @@ describe("select", () => {
{
name: string;
height: string | null;
isAdult: boolean | null;
number_of_movies: number | null;
secret_identity: string | null;
}[]
Expand Down Expand Up @@ -1524,4 +1524,39 @@ SELECT __scope_0_defaultPerson {
}));
await query.run(client);
});

test("False shape pointers are not returned", () => {
const q = e.select(e.Movie, () => ({
title: true,
rating: true,
genre: false,
}));

tc.assert<
tc.IsExact<
$infer<typeof q>,
{
title: string;
rating: number | null;
}[]
>
>(true);
});

test("Select assignment works", () => {
const q = e.select(e.Person, () => ({
name: true,
isAdult: e.bool(false),
}));

tc.assert<
tc.IsExact<
$infer<typeof q>,
{
name: string;
isAdult: false;
}[]
>
>(true);
});
});
4 changes: 2 additions & 2 deletions packages/generate/src/syntax/typesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export type computeObjectShape<
> = typeutil.flatten<
keyof Shape extends never
? { id: string }
: {
: typeutil.stripNever<{
[k in keyof Shape]: Shape[k] extends $expr_PolyShapeElement<
infer PolyType,
infer ShapeEl
Expand All @@ -385,7 +385,7 @@ export type computeObjectShape<
: [k] extends [keyof Pointers]
? shapeElementToTs<Pointers[k], Shape[k]>
: never;
}
}>
>;

export type PrimitiveType =
Expand Down

0 comments on commit f6382a5

Please sign in to comment.