Files
NapCatQQ/.pnpm-store/v3/files/41/383ad7c44ce1f56d8648e1b2fa2023a91430da27b1c430ffd6039e6fdb310229a37e937c15a3e1990c76421afc822caa1ff726e298a1a8811f7b9a1397a550
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

36 lines
1.5 KiB
Plaintext

import { CreateType } from '../create/type.mjs';
import { Literal } from '../literal/index.mjs';
import { Number } from '../number/index.mjs';
import { Computed } from '../computed/index.mjs';
import { Ref } from '../ref/index.mjs';
import { KeyOfPropertyKeys } from './keyof-property-keys.mjs';
import { UnionEvaluated } from '../union/index.mjs';
import { KeyOfFromMappedResult } from './keyof-from-mapped-result.mjs';
// ------------------------------------------------------------------
// TypeGuard
// ------------------------------------------------------------------
import { IsMappedResult, IsRef, IsComputed } from '../guard/kind.mjs';
// prettier-ignore
function FromComputed(target, parameters) {
return Computed('KeyOf', [Computed(target, parameters)]);
}
// prettier-ignore
function FromRef($ref) {
return Computed('KeyOf', [Ref($ref)]);
}
// prettier-ignore
function KeyOfFromType(type, options) {
const propertyKeys = KeyOfPropertyKeys(type);
const propertyKeyTypes = KeyOfPropertyKeysToRest(propertyKeys);
const result = UnionEvaluated(propertyKeyTypes);
return CreateType(result, options);
}
// prettier-ignore
export function KeyOfPropertyKeysToRest(propertyKeys) {
return propertyKeys.map(L => L === '[number]' ? Number() : Literal(L));
}
/** `[Json]` Creates a KeyOf type */
export function KeyOf(type, options) {
return (IsComputed(type) ? FromComputed(type.target, type.parameters) : IsRef(type) ? FromRef(type.$ref) : IsMappedResult(type) ? KeyOfFromMappedResult(type, options) : KeyOfFromType(type, options));
}