diff --git a/integration-tests/lts/casts.test.ts b/integration-tests/lts/casts.test.ts index 562e5bb55..94b330848 100644 --- a/integration-tests/lts/casts.test.ts +++ b/integration-tests/lts/casts.test.ts @@ -48,4 +48,21 @@ describe("casts", () => { tc.assert>(true); }); + + test("UUID to object cast", () => { + const expr = e.cast( + e.Movie, + e.cast(e.uuid, "00000000-0000-0000-0000-000000000000") + ); + + assert.equal( + expr.toEdgeQL(), + `(("00000000-0000-0000-0000-000000000000"))` + ); + + tc.assert>(true); + + // @ts-expect-error: does not allow assignment of non UUID + e.cast(e.Movie, 42); + }); }); diff --git a/packages/generate/src/syntax/cast.ts b/packages/generate/src/syntax/cast.ts index bb3f9a850..dff6c8c4f 100644 --- a/packages/generate/src/syntax/cast.ts +++ b/packages/generate/src/syntax/cast.ts @@ -4,6 +4,7 @@ import type { BaseType, TypeSet, ObjectTypeExpression, + ScalarType, } from "./typesystem"; import { $expressionify } from "./path"; import type { orScalarLiteral } from "./castMaps"; @@ -20,6 +21,10 @@ export function cast( : never, Cardinality.Empty >; +export function cast( + target: Target, + arg: TypeSet> +): $expr_Cast; export function cast( target: Target, expr: orScalarLiteral