Files
NapCatQQ/.pnpm-store/v3/files/a5/4f09db50850f04e506314f5d621fa556989434792e6890b23084d91a156660a10ed2beb2fe1b2805daff21a2bc06797fd116f55467eb21715b242952540536
T
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

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 { ExtractFromMappedResult } from './extract-from-mapped-result.mjs';
import { ExtractFromTemplateLiteral } from './extract-from-template-literal.mjs';
// ------------------------------------------------------------------
// TypeGuard
// ------------------------------------------------------------------
import { IsMappedResult, IsTemplateLiteral, IsUnion } from '../guard/kind.mjs';
function ExtractRest(L, R) {
const extracted = L.filter((inner) => ExtendsCheck(inner, R) !== ExtendsResult.False);
return extracted.length === 1 ? extracted[0] : Union(extracted);
}
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
export function Extract(L, R, options) {
// overloads
if (IsTemplateLiteral(L))
return CreateType(ExtractFromTemplateLiteral(L, R), options);
if (IsMappedResult(L))
return CreateType(ExtractFromMappedResult(L, R), options);
// prettier-ignore
return CreateType(IsUnion(L) ? ExtractRest(L.anyOf, R) :
ExtendsCheck(L, R) !== ExtendsResult.False ? L : Never(), options);
}