mirror of
https://github.com/strapi/strapi.git
synced 2025-09-17 04:17:21 +00:00
Remove the targetField type narrowing causing circular dep
This commit is contained in:
parent
7c7f889c8a
commit
25d521e3f1
@ -71,4 +71,14 @@ export type Any =
|
|||||||
| Attribute.Text
|
| Attribute.Text
|
||||||
| Attribute.Time
|
| Attribute.Time
|
||||||
| Attribute.Timestamp
|
| Attribute.Timestamp
|
||||||
| Attribute.UID<Common.UID.Schema | undefined>;
|
| Attribute.UID<Common.UID.Schema>;
|
||||||
|
|
||||||
|
export type PopulatableKind = Extract<
|
||||||
|
Attribute.Kind,
|
||||||
|
'relation' | 'component' | 'dynamiczone' | 'media'
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type NonPopulatableKind = Exclude<
|
||||||
|
Attribute.Kind,
|
||||||
|
'relation' | 'component' | 'dynamiczone' | 'media'
|
||||||
|
>;
|
||||||
|
@ -9,28 +9,26 @@ export interface UIDOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface UIDProperties<
|
export interface UIDProperties<
|
||||||
TOrigin extends Common.UID.Schema,
|
TTargetAttribute extends string = string,
|
||||||
TTargetAttribute extends AllowedTargetAttributes<TOrigin>,
|
|
||||||
TOptions extends UIDOptions = UIDOptions
|
TOptions extends UIDOptions = UIDOptions
|
||||||
> {
|
> {
|
||||||
targetField: TTargetAttribute;
|
targetField: TTargetAttribute;
|
||||||
options: UIDOptions & TOptions;
|
options: UIDOptions & TOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GenericUIDProperties<TOptions extends UIDOptions = UIDOptions> {
|
/**
|
||||||
targetField?: string;
|
* @param {Common.UID.Schema} [_TOrigin]
|
||||||
options: TOptions & UIDOptions;
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
export type UID<
|
export type UID<
|
||||||
TOrigin extends Common.UID.Schema | undefined = undefined,
|
// TODO: V5:
|
||||||
TTargetAttribute extends AllowedTargetAttributes<TOrigin> = AllowedTargetAttributes<TOrigin>,
|
// The TOrigin was used to narrow down the list of possible target attribute for a
|
||||||
|
// UID, but was removed due to circular dependency issues and will be removed in V5
|
||||||
|
_TOrigin extends Common.UID.Schema = never,
|
||||||
|
TTargetAttribute extends string = string,
|
||||||
TOptions extends UIDOptions = UIDOptions
|
TOptions extends UIDOptions = UIDOptions
|
||||||
> = Attribute.OfType<'uid'> &
|
> = Attribute.OfType<'uid'> &
|
||||||
// Properties
|
// Properties
|
||||||
(TOrigin extends Common.UID.Schema
|
UIDProperties<TTargetAttribute, TOptions> &
|
||||||
? UIDProperties<TOrigin, TTargetAttribute, TOptions>
|
|
||||||
: GenericUIDProperties<TOptions>) &
|
|
||||||
// Options
|
// Options
|
||||||
Attribute.ConfigurableOption &
|
Attribute.ConfigurableOption &
|
||||||
Attribute.DefaultOption<UIDValue> &
|
Attribute.DefaultOption<UIDValue> &
|
||||||
@ -38,11 +36,6 @@ export type UID<
|
|||||||
Attribute.PrivateOption &
|
Attribute.PrivateOption &
|
||||||
Attribute.RequiredOption;
|
Attribute.RequiredOption;
|
||||||
|
|
||||||
type AllowedTargetAttributes<TOrigin extends Common.UID.Schema | undefined> =
|
|
||||||
TOrigin extends Common.UID.Schema
|
|
||||||
? Utils.Guard.Never<Attribute.GetKeysByType<TOrigin, 'string' | 'text'>, string>
|
|
||||||
: never;
|
|
||||||
|
|
||||||
export type UIDValue = string;
|
export type UIDValue = string;
|
||||||
|
|
||||||
export type GetUIDValue<TAttribute extends Attribute.Attribute> = TAttribute extends UID<
|
export type GetUIDValue<TAttribute extends Attribute.Attribute> = TAttribute extends UID<
|
||||||
|
@ -4,6 +4,16 @@ export type True = true;
|
|||||||
export type False = false;
|
export type False = false;
|
||||||
export type BooleanValue = True | False;
|
export type BooleanValue = True | False;
|
||||||
|
|
||||||
|
export type IsNever<TValue> = [TValue] extends [never] ? True : False;
|
||||||
|
|
||||||
|
export type IsNotNever<TValue> = Not<IsNever<TValue>>;
|
||||||
|
|
||||||
|
export type IsTrue<TValue> = [TValue] extends [True] ? True : False;
|
||||||
|
|
||||||
|
export type IsFalse<TValue> = [TValue] extends [False] ? True : False;
|
||||||
|
|
||||||
|
export type StrictEqual<TValue, TMatch> = And<Extends<TValue, TMatch>, Extends<TMatch, TValue>>;
|
||||||
|
|
||||||
export type Extends<TLeft, TRight> = [TLeft] extends [TRight] ? True : False;
|
export type Extends<TLeft, TRight> = [TLeft] extends [TRight] ? True : False;
|
||||||
|
|
||||||
export type Not<TExpression extends BooleanValue> = If<TExpression, False, True>;
|
export type Not<TExpression extends BooleanValue> = If<TExpression, False, True>;
|
||||||
|
15
packages/core/strapi/lib/types/utils/guard.d.ts
vendored
15
packages/core/strapi/lib/types/utils/guard.d.ts
vendored
@ -1,3 +1,5 @@
|
|||||||
|
import type { Utils } from '@strapi/strapi';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign a default value `TDefault` to `TValue` if `TValue` is of type `never`
|
* Assign a default value `TDefault` to `TValue` if `TValue` is of type `never`
|
||||||
*
|
*
|
||||||
@ -11,4 +13,15 @@
|
|||||||
* type X = Never<never, string>
|
* type X = Never<never, string>
|
||||||
* // string
|
* // string
|
||||||
*/
|
*/
|
||||||
export type Never<TValue, TDefault = unknown> = [TValue] extends [never] ? TDefault : TValue;
|
export type Never<TValue, TFallback = unknown> = OfTypes<[never], TValue, TFallback>;
|
||||||
|
|
||||||
|
export type OfTypes<TTypes extends unknown[], TValue, TFallback = unknown> = TTypes extends [
|
||||||
|
infer THead extends unknown,
|
||||||
|
...infer TTail extends unknown[]
|
||||||
|
]
|
||||||
|
? Utils.Expression.If<
|
||||||
|
Utils.Expression.StrictEqual<TValue, THead>,
|
||||||
|
TFallback,
|
||||||
|
Utils.Expression.If<Utils.Array.IsNotEmpty<TTail>, OfTypes<TTail, TValue, TFallback>, TValue>
|
||||||
|
>
|
||||||
|
: never;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user