Files
NapCatQQ/.pnpm-store/v3/files/59/c0a04864ba1cd8f7f4f7cc7ecf2eb051535c7be51fbe16ddcab545785b88786a2f1d341f23bda0b522e4f01b21fdaf231ce0429c44dfbf569220ba272df0e6
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

26 lines
1.3 KiB
Plaintext

import { CreateType } from '../create/type.mjs';
import { Union } from '../union/index.mjs';
import { Never } from '../never/index.mjs';
import { ExtendsCheck, ExtendsResult } from '../extends/index.mjs';
import { ExcludeFromMappedResult } from './exclude-from-mapped-result.mjs';
import { ExcludeFromTemplateLiteral } from './exclude-from-template-literal.mjs';
// ------------------------------------------------------------------
// TypeGuard
// ------------------------------------------------------------------
import { IsMappedResult, IsTemplateLiteral, IsUnion } from '../guard/kind.mjs';
function ExcludeRest(L, R) {
const excluded = L.filter((inner) => ExtendsCheck(inner, R) === ExtendsResult.False);
return excluded.length === 1 ? excluded[0] : Union(excluded);
}
/** `[Json]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */
export function Exclude(L, R, options = {}) {
// overloads
if (IsTemplateLiteral(L))
return CreateType(ExcludeFromTemplateLiteral(L, R), options);
if (IsMappedResult(L))
return CreateType(ExcludeFromMappedResult(L, R), options);
// prettier-ignore
return CreateType(IsUnion(L) ? ExcludeRest(L.anyOf, R) :
ExtendsCheck(L, R) !== ExtendsResult.False ? Never() : L, options);
}