-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateComponentType.ts
37 lines (36 loc) · 1022 Bytes
/
CreateComponentType.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import type { IfExtends } from "hry-types/src/Any/_api";
import type { ComputeIntersection } from "hry-types/src/Object/_api";
import type { ComponentType } from "../api/DefineComponent/ReturnType/ComponentType";
import type { AddPrefix } from "./AddPrefix";
/**
* 建立一个组件类型
* @param TName 组件名称
* @param T 类型配置
* @example
* ```ts
* type $CustomA = CreateComponentType<"customA", {
* properties: { num: string };
* customEvents: { onTap: string }
* }>;
*
* // 等同下面的类型
* type $CustomA = {
* properties: {
* customA_num: string;
* };
* customEvents: {
* customA_onTap: string;
* };
* ```
*/
export type CreateComponentType<TName extends string, T extends ComponentType> = ComputeIntersection<
& IfExtends<
unknown,
T["properties"],
{},
{
properties: AddPrefix<T["properties"] & {}, TName>;
}
>
& IfExtends<unknown, T["customEvents"], {}, { customEvents: AddPrefix<T["customEvents"] & {}, TName> }>
>;