edgedb-js
edgedb-js copied to clipboard
Fix type of a computed prop in query builder
Schema
module default {
type User {
...
multi movies: Movie;
multi shows: Show;
multi documentaries: Documentary;
multi watching_list := (
select .movies union .shows
order by .year
);
multi all_media := (
select .movies union .shows union .documentaries
)
}
abstract type Content {
required year: int16;
required title: str;
}
type Movie extending Content {
required plot: str;
}
type Show extending Content {
required seasons: int16;
}
type Documentary {
required title: str;
required plot: str;
}
};
In the test below type of plot prop should be string | null.
const q = e.select(e.User, () => ({
all_media: (all_media) => ({
title: true,
...e.is(e.Content, { year: true }),
...e.is(e.Show, {
seasons: true,
}),
plot: e.op(
all_media.is(e.Movie).plot,
"??",
all_media.is(e.Documentary).plot,
),
}),
}));
type qT = $infer<typeof q>;
tc.assert<
tc.IsExact<
qT,
{
all_media: (
| {
title: string;
plot: string;
__typename: "default::Documentary";
}
| {
title: string;
plot: string;
year: number;
__typename: "default::Movie";
}
| {
title: string;
plot: string;
year: number;
seasons: number;
__typename: "default::Show";
}
)[];
}[]
>
>(true);
- EdgeDB: "5.6+adb9e77"
- EdgeDB CLI: EdgeDB CLI 5.4.0+fe09abc
edgedb-js: [email protected]@edgedb/generate): v0.5.6- Node: v22.4.1