UNPKG

@lcap/nasl

Version:

NetEase Application Specific Language

35 lines (34 loc) 1.34 kB
declare namespace nasl.error { type ErrorTypeKind = string; /** * 内部使用的基础错误类型 * @internal */ export class BaseError<in out T extends ErrorTypeKind> { readonly errorType: T & nasl.core.String; errorMsg: nasl.core.String; } export type Error = nasl.ui.Error; // 其他类型动态注入 export namespace util { type ErrorStructureShape = { errorType: ErrorTypeKind; errorMsg: nasl.core.String }; type IsStringLiteral<T extends string> = string extends T ? false : true; export type ExcludeErrors<T> = T extends (...args: any[]) => any ? (...args: Parameters<T>) => ExcludeErrorsHelper<ReturnType<T>> : ExcludeErrorsHelper<T>; type ExcludeErrorsHelper<T> = T extends ErrorStructureShape ? never : T extends nasl.error.Error ? never : T; export function excludeErrors<T>(value: T): ExcludeErrors<T>; export function excludeErrorsInTupleHead<T>( value: T ): // 泛型函数可能为 () => [返回值类型, ...剩余未填写的泛型参数(若有)] // 去除"返回值类型"中的Error,其余不变 T extends [infer Head, ...infer Tail] ? [ExcludeErrorsHelper<Head>, ...Tail] : T; type A = ExcludeErrors< { errorType: nasl.core.String; errorMsg: nasl.core.String } | nasl.error.Error >; } }