mirror of
https://github.com/strapi/strapi.git
synced 2025-09-17 12:27:33 +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.Time
|
||||
| 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<
|
||||
TOrigin extends Common.UID.Schema,
|
||||
TTargetAttribute extends AllowedTargetAttributes<TOrigin>,
|
||||
TTargetAttribute extends string = string,
|
||||
TOptions extends UIDOptions = UIDOptions
|
||||
> {
|
||||
targetField: TTargetAttribute;
|
||||
options: UIDOptions & TOptions;
|
||||
}
|
||||
|
||||
export interface GenericUIDProperties<TOptions extends UIDOptions = UIDOptions> {
|
||||
targetField?: string;
|
||||
options: TOptions & UIDOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Common.UID.Schema} [_TOrigin]
|
||||
*/
|
||||
export type UID<
|
||||
TOrigin extends Common.UID.Schema | undefined = undefined,
|
||||
TTargetAttribute extends AllowedTargetAttributes<TOrigin> = AllowedTargetAttributes<TOrigin>,
|
||||
// TODO: V5:
|
||||
// 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
|
||||
> = Attribute.OfType<'uid'> &
|
||||
// Properties
|
||||
(TOrigin extends Common.UID.Schema
|
||||
? UIDProperties<TOrigin, TTargetAttribute, TOptions>
|
||||
: GenericUIDProperties<TOptions>) &
|
||||
UIDProperties<TTargetAttribute, TOptions> &
|
||||
// Options
|
||||
Attribute.ConfigurableOption &
|
||||
Attribute.DefaultOption<UIDValue> &
|
||||
@ -38,11 +36,6 @@ export type UID<
|
||||
Attribute.PrivateOption &
|
||||
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 GetUIDValue<TAttribute extends Attribute.Attribute> = TAttribute extends UID<
|
||||
|
@ -4,6 +4,16 @@ export type True = true;
|
||||
export type False = 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 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`
|
||||
*
|
||||
@ -11,4 +13,15 @@
|
||||
* type X = Never<never, 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