Files
NapCatQQ/.pnpm-store/v3/files/4a/98472c506033c4049f6035142cbf2a45ab9b2d6098fc9bd98133ea751c1c3f7195f602c26278264112e15634b7410bd6ea0ea5c01d6b27be678aa7e3053136
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

39 lines
1.5 KiB
Plaintext

import { OptionalKind } from '../symbols/index.mjs';
import { CreateType } from '../create/type.mjs';
import { Discard } from '../discard/index.mjs';
import { Never } from '../never/index.mjs';
import { Optional } from '../optional/index.mjs';
import { IntersectCreate } from './intersect-create.mjs';
// ------------------------------------------------------------------
// TypeGuard
// ------------------------------------------------------------------
import { IsOptional, IsTransform } from '../guard/kind.mjs';
// prettier-ignore
function IsIntersectOptional(types) {
return types.every(left => IsOptional(left));
}
// prettier-ignore
function RemoveOptionalFromType(type) {
return (Discard(type, [OptionalKind]));
}
// prettier-ignore
function RemoveOptionalFromRest(types) {
return types.map(left => IsOptional(left) ? RemoveOptionalFromType(left) : left);
}
// prettier-ignore
function ResolveIntersect(types, options) {
return (IsIntersectOptional(types)
? Optional(IntersectCreate(RemoveOptionalFromRest(types), options))
: IntersectCreate(RemoveOptionalFromRest(types), options));
}
/** `[Json]` Creates an evaluated Intersect type */
export function IntersectEvaluated(types, options = {}) {
if (types.length === 1)
return CreateType(types[0], options);
if (types.length === 0)
return Never(options);
if (types.some((schema) => IsTransform(schema)))
throw new Error('Cannot intersect transform types');
return ResolveIntersect(types, options);
}