diff --git a/packages/core/strapi/lib/services/entity-service/types/params/filters/index.d.ts b/packages/core/strapi/lib/services/entity-service/types/params/filters/index.d.ts index b92c31defa..150dec4753 100644 --- a/packages/core/strapi/lib/services/entity-service/types/params/filters/index.d.ts +++ b/packages/core/strapi/lib/services/entity-service/types/params/filters/index.d.ts @@ -2,9 +2,12 @@ import type { Attribute, Common, Utils } from '@strapi/strapi'; import type * as Operator from './operators'; import type * as AttributeUtils from '../attributes'; +import type Params from '../index'; export { Operator }; +type IDKey = 'id'; + /** * Filter representation for nested attributes */ @@ -20,11 +23,17 @@ type NestedAttributeCondition< */ type AttributeCondition< TSchemaUID extends Common.UID.Schema, - TAttributeName extends Attribute.GetKeys -> = Utils.Expression.If< - Utils.Expression.IsNotNever, - // Get the filter attribute value for the given attribute - AttributeUtils.GetValue>, + TAttributeName extends IDKey | Attribute.GetKeys +> = Utils.Expression.MatchFirst< + [ + // Special catch for manually added ID attributes + [Utils.Expression.StrictEqual, Params.Attribute.ID], + [ + Utils.Expression.IsNotNever, + // Get the filter attribute value for the given attribute + AttributeUtils.GetValue>> + ] + ], // Fallback to the list of all possible scalar attributes' value if the attribute is not valid (never) AttributeUtils.ScalarValues > extends infer TAttributeValue @@ -64,11 +73,17 @@ export type ObjectNotation = { Utils.Expression.IsNotNever >, // Strongly typed representation of the filter object tree - | { [TIter in TScalarKeys]?: AttributeCondition } - | { [TIter in TNestedKeys]?: NestedAttributeCondition }, + { + [TIter in IDKey | TScalarKeys]?: AttributeCondition; + } & { + [TIter in TNestedKeys]?: NestedAttributeCondition; + }, // Generic representation of the filter object tree in case we don't have access to the attributes' list - | { [TKey in string]?: AttributeCondition } - | { [TKey in string]?: NestedAttributeCondition } + { + [TKey in string]?: + | AttributeCondition + | NestedAttributeCondition; + } > : never);