diff --git a/packages/core/strapi/lib/types/core/attributes/component.d.ts b/packages/core/strapi/lib/types/core/attributes/component.d.ts index 7dbdfdfa40..63570a8311 100644 --- a/packages/core/strapi/lib/types/core/attributes/component.d.ts +++ b/packages/core/strapi/lib/types/core/attributes/component.d.ts @@ -1,13 +1,23 @@ import { Attribute } from './base'; import { GetAttributesValues } from './utils'; -export interface ComponentAttribute extends Attribute<'component'> { +export interface ComponentAttribute + extends Attribute<'component'> { component: T; - repeatable?: boolean; + repeatable?: R; } -export type ComponentValue = GetAttributesValues; - -export type GetComponentAttributeValue = T extends ComponentAttribute - ? ComponentValue +export type ComponentValue = GetAttributesValues< + T +> extends infer V + ? R extends true + ? V[] + : V + : never; + +export type GetComponentAttributeValue = T extends ComponentAttribute< + infer U, + infer R +> + ? ComponentValue : never; diff --git a/packages/core/strapi/lib/types/core/attributes/dynamic-zone.d.ts b/packages/core/strapi/lib/types/core/attributes/dynamic-zone.d.ts index 3b6c1512cd..5daff2938c 100644 --- a/packages/core/strapi/lib/types/core/attributes/dynamic-zone.d.ts +++ b/packages/core/strapi/lib/types/core/attributes/dynamic-zone.d.ts @@ -1,4 +1,4 @@ -import { SchemaUID, ValuesOf } from '../../utils'; +import { SchemaUID, GetArrayValues } from '../../utils'; import { Attribute } from './base'; import { GetAttributesValues } from './utils'; @@ -8,7 +8,7 @@ export interface DynamicZoneAttribute } type DynamicZoneValue = Array< - ValuesOf extends infer P + GetArrayValues extends infer P ? P extends SchemaUID ? GetAttributesValues

& { __component: P } : never diff --git a/packages/core/strapi/lib/types/core/attributes/enumeration.d.ts b/packages/core/strapi/lib/types/core/attributes/enumeration.d.ts index 17c7bb6738..23e97e6e1c 100644 --- a/packages/core/strapi/lib/types/core/attributes/enumeration.d.ts +++ b/packages/core/strapi/lib/types/core/attributes/enumeration.d.ts @@ -1,11 +1,11 @@ -import { ValuesOf } from '../../utils'; +import { GetArrayValues } from '../../utils'; import { Attribute } from './base'; export interface EnumerationAttribute extends Attribute<'enumeration'> { enum: T; } -export type EnumerationValue = ValuesOf; +export type EnumerationValue = GetArrayValues; export type GetEnumerationAttributeValue = T extends EnumerationAttribute< infer U diff --git a/packages/core/strapi/lib/types/utils.d.ts b/packages/core/strapi/lib/types/utils.d.ts index b702cf4956..b1360c377b 100644 --- a/packages/core/strapi/lib/types/utils.d.ts +++ b/packages/core/strapi/lib/types/utils.d.ts @@ -6,16 +6,10 @@ /** * - * Extract the given type's values in an union type + * Extract the array values into an union type * - * @example - * type X = ValuesOf<{ foo: string, bar: number }> - * // string | number - * - * type X = ValuesOf<['foo', 'bar']> - * // 'foo' | 'bar' - */ -export type ValuesOf = T[keyof T]; + **/ +export type GetArrayValues> = T extends Array ? U : never; /** * Creates a record where every key is a string and every value is `T`