mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-03-18 12:08:49 +08:00
fix: ts 错误: 类型实例化过深,且可能无限
This commit is contained in:
34
packages/@core/base/typings/src/helper.d.ts
vendored
34
packages/@core/base/typings/src/helper.d.ts
vendored
@@ -1,20 +1,38 @@
|
|||||||
import type { ComputedRef, MaybeRef } from 'vue';
|
import type { ComputedRef, MaybeRef } from 'vue';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型级递归中增加深度计数
|
||||||
|
*/
|
||||||
|
type Increment<A extends unknown[]> = [...A, unknown];
|
||||||
/**
|
/**
|
||||||
* 深层递归所有属性为可选
|
* 深层递归所有属性为可选
|
||||||
*/
|
*/
|
||||||
type DeepPartial<T> = T extends object
|
type DeepPartial<
|
||||||
? {
|
T,
|
||||||
[P in keyof T]?: DeepPartial<T[P]>;
|
D extends number = 10,
|
||||||
}
|
C extends unknown[] = [],
|
||||||
: T;
|
> = C['length'] extends D
|
||||||
|
? T
|
||||||
|
: T extends object
|
||||||
|
? {
|
||||||
|
[P in keyof T]?: DeepPartial<T[P], D, Increment<C>>;
|
||||||
|
}
|
||||||
|
: T;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 深层递归所有属性为只读
|
* 深层递归所有属性为只读
|
||||||
*/
|
*/
|
||||||
type DeepReadonly<T> = {
|
type DeepReadonly<
|
||||||
readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
|
T,
|
||||||
};
|
D extends number = 10,
|
||||||
|
C extends unknown[] = [],
|
||||||
|
> = C['length'] extends D
|
||||||
|
? T
|
||||||
|
: T extends object
|
||||||
|
? {
|
||||||
|
readonly [P in keyof T]: DeepReadonly<T[P], D, Increment<C>>;
|
||||||
|
}
|
||||||
|
: T;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 任意类型的异步函数
|
* 任意类型的异步函数
|
||||||
|
|||||||
Reference in New Issue
Block a user