From d944d4d9c503f2c646c44250b8f4615b67abdc8e Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Fri, 22 Aug 2025 09:01:23 +0800 Subject: [PATCH] fix: enum array filter typing --- packages/runtime/src/client/crud-types.ts | 16 ++++++++++------ .../runtime/test/schemas/typing/typecheck.ts | 11 +++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/runtime/src/client/crud-types.ts b/packages/runtime/src/client/crud-types.ts index c2696069..96c57be5 100644 --- a/packages/runtime/src/client/crud-types.ts +++ b/packages/runtime/src/client/crud-types.ts @@ -218,7 +218,7 @@ export type WhereInput< ? // relation RelationFilter : FieldIsArray extends true - ? ArrayFilter> + ? ArrayFilter> : // enum GetModelFieldType extends GetEnums ? EnumFilter, ModelFieldIsOptional> @@ -246,14 +246,18 @@ type EnumFilter, Nullable e not?: EnumFilter; }; -type ArrayFilter = { - equals?: MapBaseType[]; - has?: MapBaseType; - hasEvery?: MapBaseType[]; - hasSome?: MapBaseType[]; +type ArrayFilter = { + equals?: MapScalarType[]; + has?: MapScalarType; + hasEvery?: MapScalarType[]; + hasSome?: MapScalarType[]; isEmpty?: boolean; }; +// map a scalar type (primitive and enum) to TS type +type MapScalarType = + T extends GetEnums ? keyof GetEnum : MapBaseType; + type PrimitiveFilter< Schema extends SchemaDef, T extends string, diff --git a/packages/runtime/test/schemas/typing/typecheck.ts b/packages/runtime/test/schemas/typing/typecheck.ts index 189d1c97..94961400 100644 --- a/packages/runtime/test/schemas/typing/typecheck.ts +++ b/packages/runtime/test/schemas/typing/typecheck.ts @@ -80,6 +80,17 @@ async function find() { where: { name: 'Alex' }, }); + // enum array + await client.user.findFirst({ + where: { status: { equals: [Status.ACTIVE] } }, + }); + await client.user.findFirst({ + where: { status: { has: Status.ACTIVE } }, + }); + await client.user.findFirst({ + where: { status: { hasEvery: [Status.ACTIVE] } }, + }); + await client.user.findMany({ skip: 1, take: 1,