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

37 lines
1.4 KiB
Plaintext

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IndexPropertyKeys = IndexPropertyKeys;
const index_1 = require("../template-literal/index");
// ------------------------------------------------------------------
// TypeGuard
// ------------------------------------------------------------------
const kind_1 = require("../guard/kind");
// prettier-ignore
function FromTemplateLiteral(templateLiteral) {
const keys = (0, index_1.TemplateLiteralGenerate)(templateLiteral);
return keys.map(key => key.toString());
}
// prettier-ignore
function FromUnion(types) {
const result = [];
for (const type of types)
result.push(...IndexPropertyKeys(type));
return result;
}
// prettier-ignore
function FromLiteral(literalValue) {
return ([literalValue.toString()] // TS 5.4 observes TLiteralValue as not having a toString()
);
}
/** Returns a tuple of PropertyKeys derived from the given TSchema */
// prettier-ignore
function IndexPropertyKeys(type) {
return [...new Set(((0, kind_1.IsTemplateLiteral)(type) ? FromTemplateLiteral(type) :
(0, kind_1.IsUnion)(type) ? FromUnion(type.anyOf) :
(0, kind_1.IsLiteral)(type) ? FromLiteral(type.const) :
(0, kind_1.IsNumber)(type) ? ['[number]'] :
(0, kind_1.IsInteger)(type) ? ['[number]'] :
[]))];
}