@openpkg-ts/sdk 0.54.7 → 0.54.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1781,7 +1781,7 @@ function filterSpec(spec, criteria) {
1781
1781
  };
1782
1782
  }
1783
1783
  // src/primitives/get.ts
1784
- import ts14 from "typescript";
1784
+ import ts16 from "typescript";
1785
1785
 
1786
1786
  // src/ast/type-identity.ts
1787
1787
  import * as path3 from "node:path";
@@ -1830,6 +1830,18 @@ function declKey(symbol, checker) {
1830
1830
  return;
1831
1831
  return `${decl.getSourceFile().fileName}#${decl.getStart()}`;
1832
1832
  }
1833
+ function fileLabel(fileName) {
1834
+ const base = path3.basename(fileName).replace(/(\.d)?\.[cm]?[tj]sx?$/, "");
1835
+ return base === "index" ? path3.basename(path3.dirname(fileName)) || base : base;
1836
+ }
1837
+ function namespaceLabel(decl) {
1838
+ const names = [];
1839
+ for (let node = decl?.parent;node; node = node.parent) {
1840
+ if (ts.isModuleDeclaration(node) && ts.isIdentifier(node.name))
1841
+ names.unshift(node.name.text);
1842
+ }
1843
+ return names.length > 0 ? names.join(".") : undefined;
1844
+ }
1833
1845
  function resolveTypeId(symbol, ctx) {
1834
1846
  const cached = ctx.typeIds.get(symbol);
1835
1847
  if (cached)
@@ -1853,16 +1865,49 @@ function resolveTypeId(symbol, ctx) {
1853
1865
  const owner = ctx.idOwner.get(name);
1854
1866
  if (!owner || owner === key)
1855
1867
  return claim(name);
1856
- const file = symbol.declarations?.[0]?.getSourceFile().fileName ?? "";
1857
- const scoped = `${packageLabel(file, ctx.workspacePackages)}.${name}`;
1858
- const scopedOwner = ctx.idOwner.get(scoped);
1859
- if (!scopedOwner || scopedOwner === key)
1860
- return claim(scoped);
1868
+ const decl = symbol.declarations?.[0];
1869
+ const file = decl?.getSourceFile().fileName ?? "";
1870
+ const pkg = packageLabel(file, ctx.workspacePackages);
1871
+ const ownerFile = owner.includes("#") ? owner.slice(0, owner.lastIndexOf("#")) : "";
1872
+ const scopes = pkg === packageLabel(ownerFile, ctx.workspacePackages) ? [] : [pkg];
1873
+ const namespace = namespaceLabel(decl);
1874
+ if (namespace)
1875
+ scopes.push(namespace);
1876
+ if (file)
1877
+ scopes.push(fileLabel(file));
1878
+ for (const scope of scopes) {
1879
+ const scoped = `${scope}.${name}`;
1880
+ const scopedOwner = ctx.idOwner.get(scoped);
1881
+ if (!scopedOwner || scopedOwner === key)
1882
+ return claim(scoped);
1883
+ }
1861
1884
  let n = 2;
1862
1885
  while (ctx.idOwner.has(`${name}_${n}`))
1863
1886
  n++;
1864
1887
  return claim(`${name}_${n}`);
1865
1888
  }
1889
+ var EXPORTABLE_TYPE_FLAGS = ts.SymbolFlags.Interface | ts.SymbolFlags.TypeAlias | ts.SymbolFlags.Class | ts.SymbolFlags.RegularEnum | ts.SymbolFlags.ConstEnum;
1890
+ function claimExportedTypeIds(exportedSymbols, ctx) {
1891
+ const renamed = [];
1892
+ for (const exported of exportedSymbols) {
1893
+ let target = exported;
1894
+ if (exported.flags & ts.SymbolFlags.Alias) {
1895
+ try {
1896
+ target = ctx.typeChecker.getAliasedSymbol(exported);
1897
+ } catch {
1898
+ continue;
1899
+ }
1900
+ }
1901
+ if (!(target.flags & EXPORTABLE_TYPE_FLAGS))
1902
+ continue;
1903
+ if (target.getName() === exported.getName())
1904
+ resolveTypeId(target, ctx);
1905
+ else
1906
+ renamed.push(target);
1907
+ }
1908
+ for (const target of renamed)
1909
+ resolveTypeId(target, ctx);
1910
+ }
1866
1911
  function typeRefId(type, ctx) {
1867
1912
  const symbol = type.aliasSymbol ?? type.getSymbol();
1868
1913
  if (!symbol)
@@ -2450,6 +2495,15 @@ function discoverAmbientTypePackages(baseDir) {
2450
2495
  }
2451
2496
  return found;
2452
2497
  }
2498
+ function resolutionFor(module) {
2499
+ if (module === ts3.ModuleKind.NodeNext)
2500
+ return ts3.ModuleResolutionKind.NodeNext;
2501
+ if (module >= ts3.ModuleKind.Node16 && module < ts3.ModuleKind.NodeNext)
2502
+ return ts3.ModuleResolutionKind.Node16;
2503
+ if (module >= ts3.ModuleKind.ES2015)
2504
+ return ts3.ModuleResolutionKind.Bundler;
2505
+ return;
2506
+ }
2453
2507
  function createProgram(options) {
2454
2508
  const { content } = options;
2455
2509
  const entryFile = path5.resolve(options.entryFile);
@@ -2465,7 +2519,7 @@ function createProgram(options) {
2465
2519
  const parsedConfig = ts3.parseJsonConfigFileContent(configFile.config, ts3.sys, path5.dirname(configPath));
2466
2520
  compilerOptions = { ...compilerOptions, ...parsedConfig.options };
2467
2521
  if (parsedConfig.options.module !== undefined && parsedConfig.options.moduleResolution === undefined) {
2468
- delete compilerOptions.moduleResolution;
2522
+ compilerOptions.moduleResolution = resolutionFor(parsedConfig.options.module);
2469
2523
  }
2470
2524
  additionalRootFiles = resolveProjectReferences(configPath, parsedConfig);
2471
2525
  let sourceFiles = parsedConfig.fileNames.filter((f) => !f.includes(".test.") && !f.includes(".spec.") && !f.includes("/dist/") && !f.includes("/node_modules/"));
@@ -2546,7 +2600,7 @@ function createProgram(options) {
2546
2600
  }
2547
2601
 
2548
2602
  // src/serializers/classes.ts
2549
- import ts9 from "typescript";
2603
+ import ts10 from "typescript";
2550
2604
 
2551
2605
  // src/types/parameters.ts
2552
2606
  import ts6 from "typescript";
@@ -2841,20 +2895,22 @@ function buildSchemaFromTypeNode(node, checker, ctx) {
2841
2895
  let refId = name;
2842
2896
  if (symbol && ctx) {
2843
2897
  try {
2844
- refId = namedRefId(checker.getDeclaredTypeOfSymbol(symbol), name, ctx);
2898
+ refId = typeRefId(checker.getDeclaredTypeOfSymbol(symbol), ctx) || (symbol.flags & ts5.SymbolFlags.TypeAlias ? resolveTypeId(symbol, ctx) : name);
2845
2899
  } catch {
2846
2900
  refId = name;
2847
2901
  }
2848
2902
  }
2849
2903
  return withArgs({ $ref: `#/types/${refId}` });
2850
2904
  }
2851
- return { "x-ts-type": scrubImportQualifiers(node.getText()) };
2905
+ return {
2906
+ "x-ts-type": scrubImportQualifiers(node.getText().replace(/\s+/g, " "))
2907
+ };
2852
2908
  }
2853
2909
  const t = checker.getTypeFromTypeNode(node);
2854
2910
  if (!(t.flags & ts5.TypeFlags.Any)) {
2855
2911
  return buildSchema(t, checker, ctx);
2856
2912
  }
2857
- return { "x-ts-type": scrubImportQualifiers(node.getText()) };
2913
+ return { "x-ts-type": scrubImportQualifiers(node.getText().replace(/\s+/g, " ")) };
2858
2914
  }
2859
2915
  function stripUndefinedFromType(type, checker) {
2860
2916
  if (!type.isUnion())
@@ -3038,7 +3094,20 @@ function typeNodeDefersExpansion(node, checker, program) {
3038
3094
  const symbol = resolveAliasSymbol(raw, checker, undefined, program);
3039
3095
  return shouldDeferAlias(symbol);
3040
3096
  }
3041
- function cheapTypeText(type, _checker, typeNode) {
3097
+ function isStaleTypeParameterNode(type, checker, typeNode) {
3098
+ if (type.flags & ts5.TypeFlags.TypeParameter)
3099
+ return false;
3100
+ if (!ts5.isTypeReferenceNode(typeNode) || !ts5.isIdentifier(typeNode.typeName))
3101
+ return false;
3102
+ const symbol = checker.getSymbolAtLocation(typeNode.typeName);
3103
+ return !!symbol && (symbol.flags & ts5.SymbolFlags.TypeParameter) !== 0;
3104
+ }
3105
+ function cheapTypeText(type, checker, typeNode) {
3106
+ if (typeNode && isStaleTypeParameterNode(type, checker, typeNode)) {
3107
+ const argument = type.aliasSymbol?.getName() ?? type.getSymbol()?.getName();
3108
+ if (argument && !argument.startsWith("__") && !isBuiltinGeneric(argument))
3109
+ return argument;
3110
+ }
3042
3111
  if (typeNode) {
3043
3112
  try {
3044
3113
  const text = scrubImportQualifiers(typeNode.getText().replace(/\s+/g, " ").trim());
@@ -3329,10 +3398,10 @@ function buildSchema(type, checker, ctx, typeNode) {
3329
3398
  const schema = buildSchemaInternal(type, checker, ctx, typeNode);
3330
3399
  return ensureNonEmptySchema(schema, type, checker);
3331
3400
  }
3332
- function buildMaxDepthSchema(type, checker, typeNode) {
3401
+ function buildMaxDepthSchema(type, checker, typeNode, ctx) {
3333
3402
  if (type.flags & ts5.TypeFlags.Any) {
3334
3403
  if (typeNode)
3335
- return buildSchemaFromTypeNode(typeNode, checker);
3404
+ return buildSchemaFromTypeNode(typeNode, checker, ctx);
3336
3405
  return { "x-ts-type": checker.typeToString(type) };
3337
3406
  }
3338
3407
  if (type.flags & ts5.TypeFlags.TypeParameter && !isFluentThisType(type)) {
@@ -3345,7 +3414,7 @@ function buildMaxDepthSchema(type, checker, typeNode) {
3345
3414
  return builtinSchema(name);
3346
3415
  }
3347
3416
  if (!name.startsWith("__") && !isPrimitiveName(name)) {
3348
- return { $ref: `#/types/${name}` };
3417
+ return { $ref: `#/types/${ctx ? resolveTypeId(symbol, ctx) : name}` };
3349
3418
  }
3350
3419
  }
3351
3420
  if (type.flags & ts5.TypeFlags.String)
@@ -3368,18 +3437,18 @@ function buildMaxDepthSchema(type, checker, typeNode) {
3368
3437
  };
3369
3438
  }
3370
3439
  if (type.isUnion()) {
3371
- const schemas = type.types.map((t) => buildMaxDepthSchema(t, checker));
3440
+ const schemas = type.types.map((t) => buildMaxDepthSchema(t, checker, undefined, ctx));
3372
3441
  return { anyOf: schemas };
3373
3442
  }
3374
3443
  if (type.isIntersection()) {
3375
- const schemas = type.types.map((t) => buildMaxDepthSchema(t, checker));
3444
+ const schemas = type.types.map((t) => buildMaxDepthSchema(t, checker, undefined, ctx));
3376
3445
  return { allOf: schemas };
3377
3446
  }
3378
3447
  return { type: checker.typeToString(type) };
3379
3448
  }
3380
3449
  function buildSchemaInternal(type, checker, ctx, typeNode) {
3381
3450
  if (isAtMaxDepth(ctx)) {
3382
- return buildMaxDepthSchema(type, checker, typeNode);
3451
+ return buildMaxDepthSchema(type, checker, typeNode, ctx);
3383
3452
  }
3384
3453
  if (ctx) {
3385
3454
  ctx.schemaOps += 1;
@@ -3721,7 +3790,8 @@ function buildFunctionSchema(callSignatures, checker, ctx) {
3721
3790
  return {
3722
3791
  name: param.getName(),
3723
3792
  schema: buildSchema(effectiveType, checker, ctx, decl.type),
3724
- required: !isOptional
3793
+ required: !isOptional && !decl.dotDotDotToken,
3794
+ ...decl.dotDotDotToken ? { rest: true } : {}
3725
3795
  };
3726
3796
  });
3727
3797
  const returnType = checker.getReturnTypeOfSignature(sig);
@@ -3947,6 +4017,7 @@ function extractParameters(signature, ctx) {
3947
4017
  result.push(...expandedParams);
3948
4018
  } else {
3949
4019
  const isOptional = !!decl?.questionToken || !!decl?.initializer;
4020
+ const isRest = !!decl.dotDotDotToken;
3950
4021
  const paramName = param.getName();
3951
4022
  const description = getParamDescription(paramName, jsdocTags);
3952
4023
  const schema = defer ? buildSchemaFromTypeNode(decl.type, checker, ctx) : buildSchema(isOptional ? stripUndefinedFromType(type, checker) : type, checker, ctx, decl.type);
@@ -3956,7 +4027,8 @@ function extractParameters(signature, ctx) {
3956
4027
  const paramResult = {
3957
4028
  name: paramName,
3958
4029
  schema,
3959
- required: !isOptional
4030
+ required: !isOptional && !isRest,
4031
+ ...isRest ? { rest: true } : {}
3960
4032
  };
3961
4033
  if (description) {
3962
4034
  paramResult.description = description;
@@ -4561,7 +4633,7 @@ function walkBaseTypes(type, ownMemberNames, inherited, inheritedNames, visited,
4561
4633
  continue;
4562
4634
  if (propName.startsWith("#") || propName.startsWith("__"))
4563
4635
  continue;
4564
- const member = serializeInheritedMember(prop, baseName, ctx, isStatic);
4636
+ const member = serializeInheritedMember(prop, declaringTypeName(prop) ?? baseName, ctx, isStatic);
4565
4637
  if (member) {
4566
4638
  inherited.push(member);
4567
4639
  inheritedNames.add(propName);
@@ -4570,6 +4642,12 @@ function walkBaseTypes(type, ownMemberNames, inherited, inheritedNames, visited,
4570
4642
  walkBaseTypes(baseType, ownMemberNames, inherited, inheritedNames, visited, ctx, isStatic);
4571
4643
  }
4572
4644
  }
4645
+ function declaringTypeName(prop) {
4646
+ const parent = prop.declarations?.[0]?.parent;
4647
+ if (!parent || !(ts8.isClassLike(parent) || ts8.isInterfaceDeclaration(parent)))
4648
+ return;
4649
+ return parent.name?.text;
4650
+ }
4573
4651
  function getStaticMembers(classType, checker) {
4574
4652
  const symbol = classType.getSymbol();
4575
4653
  if (!symbol)
@@ -4583,6 +4661,15 @@ function getStaticMembers(classType, checker) {
4583
4661
  return name !== "prototype" && name !== "constructor" && !name.startsWith("__");
4584
4662
  });
4585
4663
  }
4664
+ function inheritedMethodSchema(symbol, type, ctx) {
4665
+ if (!ctx.budgetExceeded) {
4666
+ return decoratePropertySchema({ "x-ts-function": true }, symbol, type, ctx.typeChecker);
4667
+ }
4668
+ return {
4669
+ "x-ts-function": true,
4670
+ ...symbol.flags & ts8.SymbolFlags.Method ? { "x-ts-method": true } : {}
4671
+ };
4672
+ }
4586
4673
  function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
4587
4674
  const { typeChecker: checker } = ctx;
4588
4675
  const name = symbol.getName();
@@ -4590,8 +4677,12 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
4590
4677
  const decl = declarations[0];
4591
4678
  if (!decl)
4592
4679
  return null;
4593
- const type = checker.getTypeOfSymbol(symbol);
4594
- registerReferencedTypes(type, ctx);
4680
+ const isOptional = !!(symbol.flags & ts8.SymbolFlags.Optional);
4681
+ const rawType = checker.getTypeOfSymbol(symbol);
4682
+ const type = isOptional ? stripUndefinedFromType(rawType, checker) : rawType;
4683
+ const registerTypes = !ctx.budgetExceeded;
4684
+ if (registerTypes)
4685
+ registerReferencedTypes(type, ctx);
4595
4686
  let visibility;
4596
4687
  if (decl && ts8.canHaveModifiers(decl)) {
4597
4688
  const modifiers = ts8.getModifiers(decl);
@@ -4609,6 +4700,7 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
4609
4700
  if (visibility === "private")
4610
4701
  return null;
4611
4702
  const { description, tags, inlineTags } = getJSDocComment(decl);
4703
+ const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
4612
4704
  let kind = "property";
4613
4705
  const callSigs = type.getCallSignatures();
4614
4706
  if (callSigs.length > 0) {
@@ -4621,6 +4713,8 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
4621
4713
  const flags = {};
4622
4714
  if (isStatic)
4623
4715
  flags.static = true;
4716
+ if (isOptional)
4717
+ flags.optional = true;
4624
4718
  if (decl && ts8.canHaveModifiers(decl)) {
4625
4719
  const modifiers = ts8.getModifiers(decl);
4626
4720
  if (modifiers?.some((m) => m.kind === ts8.SyntaxKind.ReadonlyKeyword)) {
@@ -4632,7 +4726,8 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
4632
4726
  signatures = callSigs.map((sig, index) => {
4633
4727
  const params = extractParameters(sig, ctx);
4634
4728
  const returnType = checker.getReturnTypeOfSignature(sig);
4635
- registerReferencedTypes(returnType, ctx);
4729
+ if (registerTypes)
4730
+ registerReferencedTypes(returnType, ctx);
4636
4731
  const sigDoc = getJSDocForSignature(sig, checker);
4637
4732
  return {
4638
4733
  parameters: params.length > 0 ? params : undefined,
@@ -4653,20 +4748,25 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
4653
4748
  description,
4654
4749
  tags: tags.length > 0 ? tags : undefined,
4655
4750
  visibility,
4656
- schema: kind !== "method" ? buildSchema(type, checker, ctx, declaredTypeNode(decl)) : decoratePropertySchema({ "x-ts-function": true }, symbol, type, checker),
4751
+ schema: kind !== "method" ? buildSchema(type, checker, ctx, declaredTypeNode(decl)) : inheritedMethodSchema(symbol, type, ctx),
4657
4752
  signatures,
4658
4753
  flags: Object.keys(flags).length > 0 ? flags : undefined,
4659
- ...inlineTags ? { inlineTags } : {}
4754
+ ...inlineTags ? { inlineTags } : {},
4755
+ ...deprecated ? { deprecated: true, deprecationReason } : {}
4660
4756
  };
4661
4757
  }
4662
4758
 
4663
4759
  // src/serializers/shared.ts
4760
+ import ts9 from "typescript";
4664
4761
  function extractExportMetadata(node, symbol, checker, jsdocNode) {
4665
4762
  const { deprecated, reason: deprecationReason } = isSymbolDeprecated(symbol);
4666
4763
  const { description, tags, examples, inlineTags } = getJSDocComment(jsdocNode ?? node, symbol, checker);
4667
4764
  const source = getSourceLocation(node, node.getSourceFile());
4668
4765
  return { description, tags, examples, source, deprecated, deprecationReason, inlineTags };
4669
4766
  }
4767
+ function anonymousDefaultName(node) {
4768
+ return ts9.getCombinedModifierFlags(node) & ts9.ModifierFlags.Default ? "default" : undefined;
4769
+ }
4670
4770
  function buildSignatures(callSignatures, checker, ctx) {
4671
4771
  return callSignatures.map((sig, index) => {
4672
4772
  const params = extractParameters(sig, ctx);
@@ -4691,7 +4791,7 @@ function buildSignatures(callSignatures, checker, ctx) {
4691
4791
  function serializeClass(node, ctx) {
4692
4792
  const { typeChecker: checker } = ctx;
4693
4793
  const symbol = checker.getSymbolAtLocation(node.name ?? node);
4694
- const name = symbol?.getName() ?? node.name?.getText();
4794
+ const name = symbol?.getName() ?? node.name?.getText() ?? anonymousDefaultName(node);
4695
4795
  if (!name)
4696
4796
  return null;
4697
4797
  const { description, tags, examples, source, deprecated, deprecationReason, inlineTags } = extractExportMetadata(node, symbol, checker);
@@ -4703,11 +4803,11 @@ function serializeClass(node, ctx) {
4703
4803
  const memberName = getMemberName(member);
4704
4804
  if (memberName?.startsWith("#"))
4705
4805
  continue;
4706
- if (ts9.isPropertyDeclaration(member)) {
4806
+ if (ts10.isPropertyDeclaration(member)) {
4707
4807
  const propMember = serializeProperty(member, ctx);
4708
4808
  if (propMember)
4709
4809
  members.push(propMember);
4710
- } else if (ts9.isMethodDeclaration(member)) {
4810
+ } else if (ts10.isMethodDeclaration(member)) {
4711
4811
  const methodMember = serializeMethod(member, ctx);
4712
4812
  if (methodMember?.name) {
4713
4813
  if (!methodsByName.has(methodMember.name)) {
@@ -4724,11 +4824,11 @@ function serializeClass(node, ctx) {
4724
4824
  }
4725
4825
  }
4726
4826
  }
4727
- } else if (ts9.isConstructorDeclaration(member)) {
4827
+ } else if (ts10.isConstructorDeclaration(member)) {
4728
4828
  const ctorSig = serializeConstructor(member, ctx);
4729
4829
  if (ctorSig)
4730
4830
  signatures.push(ctorSig);
4731
- } else if (ts9.isGetAccessorDeclaration(member) || ts9.isSetAccessorDeclaration(member)) {
4831
+ } else if (ts10.isGetAccessorDeclaration(member) || ts10.isSetAccessorDeclaration(member)) {
4732
4832
  const accessorMember = serializeAccessor(member, ctx);
4733
4833
  if (accessorMember)
4734
4834
  members.push(accessorMember);
@@ -4752,8 +4852,8 @@ function serializeClass(node, ctx) {
4752
4852
  const extendsClause = getExtendsClause(node, checker);
4753
4853
  const implementsClause = getImplementsClause(node, checker);
4754
4854
  const classFlags = {};
4755
- const classModifiers = ts9.getModifiers(node);
4756
- if (classModifiers?.some((m) => m.kind === ts9.SyntaxKind.AbstractKeyword)) {
4855
+ const classModifiers = ts10.getModifiers(node);
4856
+ if (classModifiers?.some((m) => m.kind === ts10.SyntaxKind.AbstractKeyword)) {
4757
4857
  classFlags.abstract = true;
4758
4858
  }
4759
4859
  return {
@@ -4775,37 +4875,37 @@ function serializeClass(node, ctx) {
4775
4875
  };
4776
4876
  }
4777
4877
  function getMemberName(member) {
4778
- if (ts9.isConstructorDeclaration(member))
4878
+ if (ts10.isConstructorDeclaration(member))
4779
4879
  return "constructor";
4780
4880
  if (!member.name)
4781
4881
  return;
4782
- if (ts9.isIdentifier(member.name))
4882
+ if (ts10.isIdentifier(member.name))
4783
4883
  return member.name.text;
4784
- if (ts9.isPrivateIdentifier(member.name))
4884
+ if (ts10.isPrivateIdentifier(member.name))
4785
4885
  return member.name.text;
4786
4886
  return member.name.getText();
4787
4887
  }
4788
4888
  function getVisibility(member) {
4789
- const modifiers = ts9.canHaveModifiers(member) ? ts9.getModifiers(member) : undefined;
4889
+ const modifiers = ts10.canHaveModifiers(member) ? ts10.getModifiers(member) : undefined;
4790
4890
  if (!modifiers)
4791
4891
  return;
4792
4892
  for (const mod of modifiers) {
4793
- if (mod.kind === ts9.SyntaxKind.PrivateKeyword)
4893
+ if (mod.kind === ts10.SyntaxKind.PrivateKeyword)
4794
4894
  return "private";
4795
- if (mod.kind === ts9.SyntaxKind.ProtectedKeyword)
4895
+ if (mod.kind === ts10.SyntaxKind.ProtectedKeyword)
4796
4896
  return "protected";
4797
- if (mod.kind === ts9.SyntaxKind.PublicKeyword)
4897
+ if (mod.kind === ts10.SyntaxKind.PublicKeyword)
4798
4898
  return "public";
4799
4899
  }
4800
4900
  return;
4801
4901
  }
4802
4902
  function isStatic(member) {
4803
- const modifiers = ts9.canHaveModifiers(member) ? ts9.getModifiers(member) : undefined;
4804
- return modifiers?.some((m) => m.kind === ts9.SyntaxKind.StaticKeyword) ?? false;
4903
+ const modifiers = ts10.canHaveModifiers(member) ? ts10.getModifiers(member) : undefined;
4904
+ return modifiers?.some((m) => m.kind === ts10.SyntaxKind.StaticKeyword) ?? false;
4805
4905
  }
4806
4906
  function isReadonly(member) {
4807
- const modifiers = ts9.canHaveModifiers(member) ? ts9.getModifiers(member) : undefined;
4808
- return modifiers?.some((m) => m.kind === ts9.SyntaxKind.ReadonlyKeyword) ?? false;
4907
+ const modifiers = ts10.canHaveModifiers(member) ? ts10.getModifiers(member) : undefined;
4908
+ return modifiers?.some((m) => m.kind === ts10.SyntaxKind.ReadonlyKeyword) ?? false;
4809
4909
  }
4810
4910
  function serializeProperty(node, ctx) {
4811
4911
  const { typeChecker: checker } = ctx;
@@ -4864,11 +4964,11 @@ function serializeMethod(node, ctx) {
4864
4964
  if (node.asteriskToken)
4865
4965
  flags.generator = true;
4866
4966
  flags.methodSyntax = true;
4867
- const modifiers = ts9.getModifiers(node);
4868
- if (modifiers?.some((m) => m.kind === ts9.SyntaxKind.AsyncKeyword)) {
4967
+ const modifiers = ts10.getModifiers(node);
4968
+ if (modifiers?.some((m) => m.kind === ts10.SyntaxKind.AsyncKeyword)) {
4869
4969
  flags.async = true;
4870
4970
  }
4871
- if (modifiers?.some((m) => m.kind === ts9.SyntaxKind.AbstractKeyword)) {
4971
+ if (modifiers?.some((m) => m.kind === ts10.SyntaxKind.AbstractKeyword)) {
4872
4972
  flags.abstract = true;
4873
4973
  }
4874
4974
  const symbol = checker.getSymbolAtLocation(node.name ?? node);
@@ -4894,8 +4994,18 @@ function serializeConstructor(node, ctx) {
4894
4994
  return null;
4895
4995
  return serializeConstructorSignature(node, sig, ctx);
4896
4996
  }
4997
+ function serializeConstructSignatures(sigs, ctx) {
4998
+ return sigs.map((sig, index) => {
4999
+ const typeParameters = extractTypeParametersFromSignature(sig, ctx.typeChecker);
5000
+ return {
5001
+ ...serializeConstructorSignature(sig.getDeclaration(), sig, ctx),
5002
+ ...typeParameters ? { typeParameters } : {},
5003
+ ...sigs.length > 1 ? { overloadIndex: index } : {}
5004
+ };
5005
+ });
5006
+ }
4897
5007
  function serializeConstructorSignature(node, sig, ctx) {
4898
- const { description, tags, examples, inlineTags } = getJSDocComment(node);
5008
+ const { description, tags, examples, inlineTags } = node ? getJSDocComment(node) : { description: undefined, tags: [], examples: [], inlineTags: undefined };
4899
5009
  const params = extractParameters(sig, ctx);
4900
5010
  return {
4901
5011
  description,
@@ -4907,7 +5017,7 @@ function serializeConstructorSignature(node, sig, ctx) {
4907
5017
  }
4908
5018
  function serializeInheritedConstructors(node, ctx) {
4909
5019
  const { typeChecker: checker } = ctx;
4910
- const hasExtends = node.heritageClauses?.some((c) => c.token === ts9.SyntaxKind.ExtendsKeyword);
5020
+ const hasExtends = node.heritageClauses?.some((c) => c.token === ts10.SyntaxKind.ExtendsKeyword);
4911
5021
  if (!hasExtends)
4912
5022
  return [];
4913
5023
  const symbol = checker.getSymbolAtLocation(node.name ?? node);
@@ -4916,11 +5026,11 @@ function serializeInheritedConstructors(node, ctx) {
4916
5026
  const staticType = checker.getTypeOfSymbolAtLocation(symbol, node);
4917
5027
  const ctorSigs = staticType.getConstructSignatures().filter((sig) => {
4918
5028
  const decl = sig.getDeclaration();
4919
- return decl !== undefined && ts9.isConstructorDeclaration(decl);
5029
+ return decl !== undefined && ts10.isConstructorDeclaration(decl);
4920
5030
  });
4921
5031
  return ctorSigs.map((sig, index) => {
4922
5032
  const decl = sig.getDeclaration();
4923
- const owner = ts9.isClassLike(decl.parent) ? decl.parent.name?.text : undefined;
5033
+ const owner = ts10.isClassLike(decl.parent) ? decl.parent.name?.text : undefined;
4924
5034
  return {
4925
5035
  ...serializeConstructorSignature(decl, sig, ctx),
4926
5036
  ...owner ? { inheritedFrom: owner } : {},
@@ -4939,14 +5049,14 @@ function serializeAccessor(node, ctx) {
4939
5049
  return null;
4940
5050
  }
4941
5051
  const type = checker.getTypeAtLocation(node);
4942
- const schema = buildSchema(type, checker, ctx, ts9.isGetAccessorDeclaration(node) ? node.type : undefined);
5052
+ const schema = buildSchema(type, checker, ctx, ts10.isGetAccessorDeclaration(node) ? node.type : undefined);
4943
5053
  registerReferencedTypes(type, ctx);
4944
- const kind = ts9.isGetAccessorDeclaration(node) ? "getter" : "setter";
5054
+ const kind = ts10.isGetAccessorDeclaration(node) ? "getter" : "setter";
4945
5055
  const flags = {};
4946
5056
  if (isStatic(node))
4947
5057
  flags.static = true;
4948
5058
  let signatures;
4949
- if (ts9.isSetAccessorDeclaration(node) && node.parameters.length > 0) {
5059
+ if (ts10.isSetAccessorDeclaration(node) && node.parameters.length > 0) {
4950
5060
  const param = node.parameters[0];
4951
5061
  const paramName = param.name.getText();
4952
5062
  const paramType = checker.getTypeAtLocation(param);
@@ -4979,7 +5089,7 @@ function getExtendsClause(node, checker) {
4979
5089
  if (!node.heritageClauses)
4980
5090
  return;
4981
5091
  for (const clause of node.heritageClauses) {
4982
- if (clause.token === ts9.SyntaxKind.ExtendsKeyword) {
5092
+ if (clause.token === ts10.SyntaxKind.ExtendsKeyword) {
4983
5093
  const expr = clause.types[0];
4984
5094
  if (expr) {
4985
5095
  const type = checker.getTypeAtLocation(expr);
@@ -4994,7 +5104,7 @@ function getImplementsClause(node, checker) {
4994
5104
  if (!node.heritageClauses)
4995
5105
  return;
4996
5106
  for (const clause of node.heritageClauses) {
4997
- if (clause.token === ts9.SyntaxKind.ImplementsKeyword) {
5107
+ if (clause.token === ts10.SyntaxKind.ImplementsKeyword) {
4998
5108
  return clause.types.map((expr) => {
4999
5109
  const type = checker.getTypeAtLocation(expr);
5000
5110
  const symbol = type.getSymbol();
@@ -5057,16 +5167,16 @@ function serializeEnum(node, ctx) {
5057
5167
  }
5058
5168
 
5059
5169
  // src/serializers/functions.ts
5060
- import ts10 from "typescript";
5170
+ import ts11 from "typescript";
5061
5171
  function buildReturnSchema(sig, ctx) {
5062
5172
  const returnType = ctx.typeChecker.getReturnTypeOfSignature(sig);
5063
5173
  registerReferencedTypes(returnType, ctx);
5064
5174
  const schema = buildSchema(returnType, ctx.typeChecker, ctx, typeNodeOfSignature(sig));
5065
5175
  const declaration = sig.getDeclaration();
5066
- if (declaration && ts10.isFunctionLike(declaration) && declaration.type) {
5176
+ if (declaration && ts11.isFunctionLike(declaration) && declaration.type) {
5067
5177
  const returnTypeNode = declaration.type;
5068
- if (ts10.isTypePredicateNode(returnTypeNode)) {
5069
- const parameterName = ts10.isIdentifier(returnTypeNode.parameterName) ? returnTypeNode.parameterName.text : returnTypeNode.parameterName.getText();
5178
+ if (ts11.isTypePredicateNode(returnTypeNode)) {
5179
+ const parameterName = ts11.isIdentifier(returnTypeNode.parameterName) ? returnTypeNode.parameterName.text : returnTypeNode.parameterName.getText();
5070
5180
  let predicateTypeSchema = { type: "unknown" };
5071
5181
  if (returnTypeNode.type) {
5072
5182
  const predicateType = ctx.typeChecker.getTypeAtLocation(returnTypeNode.type);
@@ -5087,10 +5197,10 @@ function buildReturnSchema(sig, ctx) {
5087
5197
  return { schema };
5088
5198
  }
5089
5199
  function functionSignatureDecls(node, ctx) {
5090
- if (!ts10.isFunctionDeclaration(node) || !node.name)
5200
+ if (!ts11.isFunctionDeclaration(node) || !node.name)
5091
5201
  return [node];
5092
5202
  const symbol = ctx.typeChecker.getSymbolAtLocation(node.name);
5093
- const fns = (symbol?.declarations ?? []).filter(ts10.isFunctionDeclaration);
5203
+ const fns = (symbol?.declarations ?? []).filter(ts11.isFunctionDeclaration);
5094
5204
  const overloads = fns.filter((d) => !d.body);
5095
5205
  return overloads.length > 0 ? overloads : [node];
5096
5206
  }
@@ -5122,14 +5232,15 @@ function schemaFromTypeNode(node, ctx) {
5122
5232
  return buildSchema(ctx.typeChecker.getTypeFromTypeNode(node), ctx.typeChecker, ctx, node);
5123
5233
  }
5124
5234
  function parametersFromAst(decl, ctx) {
5125
- const jsdocTags = ts10.getJSDocTags(decl);
5235
+ const jsdocTags = ts11.getJSDocTags(decl);
5126
5236
  return decl.parameters.map((p) => {
5127
- const name = ts10.isIdentifier(p.name) ? p.name.text : p.name.getText();
5237
+ const name = ts11.isIdentifier(p.name) ? p.name.text : p.name.getText();
5128
5238
  const isOptional = !!p.questionToken || !!p.initializer;
5129
5239
  const param = {
5130
5240
  name,
5131
5241
  schema: schemaFromTypeNode(p.type, ctx),
5132
- required: !isOptional
5242
+ required: !isOptional && !p.dotDotDotToken,
5243
+ ...p.dotDotDotToken ? { rest: true } : {}
5133
5244
  };
5134
5245
  const description = getParamDescription(name, jsdocTags);
5135
5246
  if (description)
@@ -5137,11 +5248,10 @@ function parametersFromAst(decl, ctx) {
5137
5248
  return param;
5138
5249
  });
5139
5250
  }
5140
- function signaturesFromAst(node, ctx) {
5141
- const decls = functionSignatureDecls(node, ctx);
5251
+ function signaturesFromAst(decls, ctx) {
5142
5252
  return decls.map((decl, index) => {
5143
5253
  const sigDoc = getJSDocComment(decl);
5144
- const sigTypeParams = ts10.isFunctionDeclaration(decl) || ts10.isArrowFunction(decl) || ts10.isFunctionExpression(decl) ? extractTypeParameters(decl, ctx.typeChecker) : undefined;
5254
+ const sigTypeParams = ts11.isFunctionDeclaration(decl) || ts11.isArrowFunction(decl) || ts11.isFunctionExpression(decl) || ts11.isFunctionTypeNode(decl) ? extractTypeParameters(decl, ctx.typeChecker) : undefined;
5145
5255
  const returns = { schema: schemaFromTypeNode(decl.type, ctx) };
5146
5256
  return {
5147
5257
  parameters: parametersFromAst(decl, ctx),
@@ -5154,9 +5264,7 @@ function signaturesFromAst(node, ctx) {
5154
5264
  };
5155
5265
  });
5156
5266
  }
5157
- function signaturesFromChecker(node, ctx) {
5158
- const type = ctx.typeChecker.getTypeAtLocation(node);
5159
- const callSignatures = type.getCallSignatures();
5267
+ function signaturesFromChecker(callSignatures, ctx) {
5160
5268
  return callSignatures.map((sig, index) => {
5161
5269
  const sigDoc = getJSDocForSignature(sig, ctx.typeChecker);
5162
5270
  const sigTypeParams = extractTypeParametersFromSignature(sig, ctx.typeChecker);
@@ -5171,17 +5279,31 @@ function signaturesFromChecker(node, ctx) {
5171
5279
  };
5172
5280
  });
5173
5281
  }
5174
- function serializeFunctionExport(node, ctx, nameOverride) {
5282
+ function unwrapParens(node) {
5283
+ return ts11.isParenthesizedTypeNode(node) ? unwrapParens(node.type) : node;
5284
+ }
5285
+ function signaturesFromDeclaredType(typeNode, ctx) {
5286
+ const inner = unwrapParens(typeNode);
5287
+ if (ts11.isFunctionTypeNode(inner) && signatureDeclDefers(inner, ctx)) {
5288
+ return signaturesFromAst([inner], ctx);
5289
+ }
5290
+ if (typeNodeDefersExpansion(inner, ctx.typeChecker, ctx.program))
5291
+ return;
5292
+ const callSignatures = ctx.typeChecker.getTypeFromTypeNode(inner).getCallSignatures();
5293
+ return callSignatures.length > 0 ? signaturesFromChecker(callSignatures, ctx) : undefined;
5294
+ }
5295
+ function serializeFunctionExport(node, ctx, nameOverride, declaredType, jsdocNode) {
5175
5296
  const symbol = ctx.typeChecker.getSymbolAtLocation(node.name ?? node);
5176
- const name = nameOverride ?? symbol?.getName() ?? node.name?.getText();
5297
+ const name = nameOverride ?? symbol?.getName() ?? node.name?.getText() ?? anonymousDefaultName(node);
5177
5298
  if (!name)
5178
5299
  return null;
5179
- const { description, tags, examples, source, deprecated, deprecationReason, inlineTags } = extractExportMetadata(node, symbol, ctx.typeChecker);
5180
- const typeParameters = extractTypeParameters(node, ctx.typeChecker);
5181
- const signatures = anySignatureDefers(node, ctx) ? signaturesFromAst(node, ctx) : signaturesFromChecker(node, ctx);
5300
+ const { description, tags, examples, source, deprecated, deprecationReason, inlineTags } = extractExportMetadata(node, symbol, ctx.typeChecker, jsdocNode);
5301
+ const declaredFn = declaredType && unwrapParens(declaredType);
5302
+ const typeParameters = extractTypeParameters(declaredFn && ts11.isFunctionTypeNode(declaredFn) ? declaredFn : node, ctx.typeChecker);
5303
+ const signatures = (declaredType && signaturesFromDeclaredType(declaredType, ctx)) ?? (anySignatureDefers(node, ctx) ? signaturesFromAst(functionSignatureDecls(node, ctx), ctx) : signaturesFromChecker(ctx.typeChecker.getTypeAtLocation(node).getCallSignatures(), ctx));
5182
5304
  const flags = {};
5183
- const modifiers = ts10.getModifiers(node);
5184
- if (modifiers?.some((m) => m.kind === ts10.SyntaxKind.AsyncKeyword)) {
5305
+ const modifiers = ts11.getModifiers(node);
5306
+ if (modifiers?.some((m) => m.kind === ts11.SyntaxKind.AsyncKeyword)) {
5185
5307
  flags.async = true;
5186
5308
  }
5187
5309
  if (node.asteriskToken) {
@@ -5204,7 +5326,7 @@ function serializeFunctionExport(node, ctx, nameOverride) {
5204
5326
  }
5205
5327
 
5206
5328
  // src/serializers/interfaces.ts
5207
- import ts11 from "typescript";
5329
+ import ts12 from "typescript";
5208
5330
  function serializeInterface(node, ctx) {
5209
5331
  const { typeChecker: checker } = ctx;
5210
5332
  const symbol = checker.getSymbolAtLocation(node.name ?? node);
@@ -5213,15 +5335,35 @@ function serializeInterface(node, ctx) {
5213
5335
  return null;
5214
5336
  const { description, tags, examples, source, deprecated, deprecationReason, inlineTags } = extractExportMetadata(node, symbol, checker);
5215
5337
  const typeParameters = extractTypeParameters(node, checker);
5338
+ const { members, callSignatureMember } = serializeTypeElements(node.members, ctx);
5339
+ const extendsClause = getInterfaceExtends(node, checker);
5340
+ const exportSignatures = callSignatureMember?.signatures && callSignatureMember.signatures.length > 0 ? callSignatureMember.signatures : undefined;
5341
+ return {
5342
+ id: name,
5343
+ name,
5344
+ kind: "interface",
5345
+ description,
5346
+ tags,
5347
+ source,
5348
+ typeParameters,
5349
+ members: members.length > 0 ? members : undefined,
5350
+ signatures: exportSignatures,
5351
+ extends: extendsClause,
5352
+ ...deprecated ? { deprecated: true, deprecationReason } : {},
5353
+ ...examples.length > 0 ? { examples } : {},
5354
+ ...inlineTags ? { inlineTags } : {}
5355
+ };
5356
+ }
5357
+ function serializeTypeElements(elements, ctx) {
5216
5358
  const members = [];
5217
5359
  const methodsByName = new Map;
5218
5360
  let callSignatureMember = null;
5219
- for (const member of node.members) {
5220
- if (ts11.isPropertySignature(member)) {
5361
+ for (const member of elements) {
5362
+ if (ts12.isPropertySignature(member)) {
5221
5363
  const propMember = serializePropertySignature(member, ctx);
5222
5364
  if (propMember)
5223
5365
  members.push(propMember);
5224
- } else if (ts11.isMethodSignature(member)) {
5366
+ } else if (ts12.isMethodSignature(member)) {
5225
5367
  const methodMember = serializeMethodSignature(member, ctx);
5226
5368
  if (methodMember?.name && methodMember.signatures) {
5227
5369
  const existing = methodsByName.get(methodMember.name);
@@ -5242,7 +5384,7 @@ function serializeInterface(node, ctx) {
5242
5384
  methodsByName.set(methodMember.name, methodMember);
5243
5385
  }
5244
5386
  }
5245
- } else if (ts11.isCallSignatureDeclaration(member)) {
5387
+ } else if (ts12.isCallSignatureDeclaration(member)) {
5246
5388
  const callSig = serializeCallSignature(member, ctx);
5247
5389
  if (callSig?.signatures) {
5248
5390
  if (callSignatureMember?.signatures) {
@@ -5265,7 +5407,7 @@ function serializeInterface(node, ctx) {
5265
5407
  callSignatureMember = callSig;
5266
5408
  }
5267
5409
  }
5268
- } else if (ts11.isIndexSignatureDeclaration(member)) {
5410
+ } else if (ts12.isIndexSignatureDeclaration(member)) {
5269
5411
  const indexMember = serializeIndexSignature(member, ctx);
5270
5412
  if (indexMember)
5271
5413
  members.push(indexMember);
@@ -5275,22 +5417,31 @@ function serializeInterface(node, ctx) {
5275
5417
  members.push(callSignatureMember);
5276
5418
  }
5277
5419
  members.push(...methodsByName.values());
5278
- const extendsClause = getInterfaceExtends(node, checker);
5279
- const exportSignatures = callSignatureMember?.signatures && callSignatureMember.signatures.length > 0 ? callSignatureMember.signatures : undefined;
5420
+ return { members, callSignatureMember };
5421
+ }
5422
+ function serializeMergedTypeSide(symbol, ctx) {
5423
+ const { typeChecker: checker } = ctx;
5424
+ const declarations = symbol.declarations ?? [];
5425
+ const interfaces = declarations.filter(ts12.isInterfaceDeclaration);
5426
+ const alias = declarations.find(ts12.isTypeAliasDeclaration);
5427
+ const typeDecl = interfaces[0] ?? alias;
5428
+ if (!typeDecl)
5429
+ return;
5430
+ const elements = interfaces.length > 0 ? interfaces.flatMap((decl) => [...decl.members]) : alias && ts12.isTypeLiteralNode(alias.type) ? [...alias.type.members] : [];
5431
+ const { members } = serializeTypeElements(elements, ctx);
5432
+ if (interfaces.length > 0) {
5433
+ const ownNames = new Set(members.flatMap((m) => m.name ? [m.name] : []));
5434
+ members.push(...getInheritedMembers(checker.getDeclaredTypeOfSymbol(symbol), ownNames, ctx, false));
5435
+ }
5436
+ if (members.length === 0)
5437
+ return;
5438
+ const { description, tags } = getJSDocComment(typeDecl);
5280
5439
  return {
5281
- id: name,
5282
- name,
5283
- kind: "interface",
5440
+ members,
5441
+ extends: interfaces.map((decl) => getInterfaceExtends(decl, checker)).find(Boolean),
5442
+ typeParameters: extractTypeParameters(typeDecl, checker),
5284
5443
  description,
5285
- tags,
5286
- source,
5287
- typeParameters,
5288
- members: members.length > 0 ? members : undefined,
5289
- signatures: exportSignatures,
5290
- extends: extendsClause,
5291
- ...deprecated ? { deprecated: true, deprecationReason } : {},
5292
- ...examples.length > 0 ? { examples } : {},
5293
- ...inlineTags ? { inlineTags } : {}
5444
+ tags
5294
5445
  };
5295
5446
  }
5296
5447
  function serializePropertySignature(node, ctx) {
@@ -5304,7 +5455,7 @@ function serializePropertySignature(node, ctx) {
5304
5455
  const flags = {};
5305
5456
  if (node.questionToken)
5306
5457
  flags.optional = true;
5307
- if (node.modifiers?.some((m) => m.kind === ts11.SyntaxKind.ReadonlyKeyword)) {
5458
+ if (node.modifiers?.some((m) => m.kind === ts12.SyntaxKind.ReadonlyKeyword)) {
5308
5459
  flags.readonly = true;
5309
5460
  }
5310
5461
  const symbol = checker.getSymbolAtLocation(node.name);
@@ -5327,7 +5478,8 @@ function serializeMethodSignature(node, ctx) {
5327
5478
  const { typeChecker: checker } = ctx;
5328
5479
  const name = node.name.getText();
5329
5480
  const { description, tags, inlineTags } = getJSDocComment(node);
5330
- const type = checker.getTypeAtLocation(node);
5481
+ const rawType = checker.getTypeAtLocation(node);
5482
+ const type = node.questionToken ? stripUndefinedFromType(rawType, checker) : rawType;
5331
5483
  const callSignatures = type.getCallSignatures();
5332
5484
  const signatures = buildSignatures(callSignatures, checker, ctx);
5333
5485
  const flags = {};
@@ -5396,7 +5548,7 @@ function getInterfaceExtends(node, checker) {
5396
5548
  if (!node.heritageClauses)
5397
5549
  return;
5398
5550
  for (const clause of node.heritageClauses) {
5399
- if (clause.token === ts11.SyntaxKind.ExtendsKeyword && clause.types.length > 0) {
5551
+ if (clause.token === ts12.SyntaxKind.ExtendsKeyword && clause.types.length > 0) {
5400
5552
  const names = clause.types.map((expr) => {
5401
5553
  const type = checker.getTypeAtLocation(expr);
5402
5554
  return type.getSymbol()?.getName() ?? expr.expression.getText();
@@ -5408,7 +5560,7 @@ function getInterfaceExtends(node, checker) {
5408
5560
  }
5409
5561
 
5410
5562
  // src/serializers/type-aliases.ts
5411
- import ts12 from "typescript";
5563
+ import ts13 from "typescript";
5412
5564
  function buildIntersectionSchemaFromNode(node, ctx) {
5413
5565
  const types = node.types;
5414
5566
  const schemas = [];
@@ -5436,7 +5588,7 @@ function serializeTypeAlias(node, ctx) {
5436
5588
  registerReferencedTypes(type, ctx);
5437
5589
  let schema;
5438
5590
  let members;
5439
- if (ts12.isIntersectionTypeNode(node.type)) {
5591
+ if (ts13.isIntersectionTypeNode(node.type)) {
5440
5592
  schema = buildIntersectionSchemaFromNode(node.type, ctx);
5441
5593
  if (type.getProperties().length > 0 && type.getCallSignatures().length === 0) {
5442
5594
  members = serializeResolvedMembers(type, node, ctx);
@@ -5446,7 +5598,7 @@ function serializeTypeAlias(node, ctx) {
5446
5598
  if (type.getProperties().length > 0) {
5447
5599
  members = serializeResolvedMembers(type, node, ctx);
5448
5600
  }
5449
- } else if ((ts12.isMappedTypeNode(node.type) || ts12.isConditionalTypeNode(node.type)) && type.getProperties().length > 0 && type.getCallSignatures().length === 0 && !(type.flags & ts12.TypeFlags.Conditional) && !(type.flags & (ts12.TypeFlags.StringLike | ts12.TypeFlags.NumberLike))) {
5601
+ } else if ((ts13.isMappedTypeNode(node.type) || ts13.isConditionalTypeNode(node.type)) && type.getProperties().length > 0 && type.getCallSignatures().length === 0 && !(type.flags & ts13.TypeFlags.Conditional) && !(type.flags & (ts13.TypeFlags.StringLike | ts13.TypeFlags.NumberLike))) {
5450
5602
  schema = buildObjectSchema(type.getProperties(), ctx.typeChecker, ctx, type);
5451
5603
  members = serializeResolvedMembers(type, node, ctx);
5452
5604
  } else {
@@ -5456,7 +5608,7 @@ function serializeTypeAlias(node, ctx) {
5456
5608
  }
5457
5609
  }
5458
5610
  if (shouldEmitAliasTypeText(node.type) && typeof schema === "object" && schema !== null && !("x-ts-type" in schema)) {
5459
- const text = renderTypeText(type, ctx.typeChecker, node, ts12.TypeFormatFlags.InTypeAlias);
5611
+ const text = renderTypeText(type, ctx.typeChecker, node, ts13.TypeFormatFlags.InTypeAlias);
5460
5612
  if (!PRIMITIVES.has(text) && text !== name) {
5461
5613
  schema["x-ts-type"] = text;
5462
5614
  const declared = writtenTypeText(declaredTypeNode(node));
@@ -5482,12 +5634,12 @@ function serializeTypeAlias(node, ctx) {
5482
5634
  }
5483
5635
  function isObjectShapedAlias(type, ctx) {
5484
5636
  const { typeChecker: checker } = ctx;
5485
- if (!(type.flags & ts12.TypeFlags.Object))
5637
+ if (!(type.flags & ts13.TypeFlags.Object))
5486
5638
  return false;
5487
5639
  if (checker.isArrayType(type) || checker.isTupleType(type))
5488
5640
  return false;
5489
5641
  const objectFlags = type.objectFlags;
5490
- if (!(objectFlags & ts12.ObjectFlags.Mapped)) {
5642
+ if (!(objectFlags & ts13.ObjectFlags.Mapped)) {
5491
5643
  const targetSymbol = type.target?.getSymbol?.() ?? type.getSymbol();
5492
5644
  if (isBuiltinSymbol(targetSymbol))
5493
5645
  return false;
@@ -5495,19 +5647,19 @@ function isObjectShapedAlias(type, ctx) {
5495
5647
  return type.getProperties().length > 0 && type.getCallSignatures().length === 0;
5496
5648
  }
5497
5649
  function isInlineFunctionAlias(typeNode) {
5498
- return ts12.isFunctionTypeNode(typeNode) || ts12.isTypeLiteralNode(typeNode) && typeNode.members.some(ts12.isCallSignatureDeclaration);
5650
+ return ts13.isFunctionTypeNode(typeNode) || ts13.isTypeLiteralNode(typeNode) && typeNode.members.some(ts13.isCallSignatureDeclaration);
5499
5651
  }
5500
5652
  function buildConditionalArmDocs(typeNode, checker) {
5501
5653
  const docs = new Map;
5502
- if (!ts12.isMappedTypeNode(typeNode) || !typeNode.type)
5654
+ if (!ts13.isMappedTypeNode(typeNode) || !typeNode.type)
5503
5655
  return docs;
5504
5656
  const literalKeys = (extendsType) => {
5505
5657
  const keys = [];
5506
5658
  const visit = (n) => {
5507
- if (ts12.isUnionTypeNode(n)) {
5659
+ if (ts13.isUnionTypeNode(n)) {
5508
5660
  for (const member of n.types)
5509
5661
  visit(member);
5510
- } else if (ts12.isLiteralTypeNode(n) && ts12.isStringLiteral(n.literal)) {
5662
+ } else if (ts13.isLiteralTypeNode(n) && ts13.isStringLiteral(n.literal)) {
5511
5663
  keys.push(n.literal.text);
5512
5664
  }
5513
5665
  };
@@ -5515,12 +5667,12 @@ function buildConditionalArmDocs(typeNode, checker) {
5515
5667
  return keys;
5516
5668
  };
5517
5669
  const armDoc = (armType) => {
5518
- if (!ts12.isTypeReferenceNode(armType))
5670
+ if (!ts13.isTypeReferenceNode(armType))
5519
5671
  return;
5520
5672
  const symbol = checker.getSymbolAtLocation(armType.typeName);
5521
5673
  if (!symbol)
5522
5674
  return;
5523
- const target = symbol.flags & ts12.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
5675
+ const target = symbol.flags & ts13.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
5524
5676
  const { deprecated, reason } = isSymbolDeprecated(target);
5525
5677
  const targetDecl = target.getDeclarations()?.[0];
5526
5678
  const description = targetDecl ? getJSDocComment(targetDecl, target, checker).description : undefined;
@@ -5529,7 +5681,7 @@ function buildConditionalArmDocs(typeNode, checker) {
5529
5681
  return { deprecated, deprecationReason: reason, description };
5530
5682
  };
5531
5683
  let current = typeNode.type;
5532
- while (current && ts12.isConditionalTypeNode(current)) {
5684
+ while (current && ts13.isConditionalTypeNode(current)) {
5533
5685
  const doc = armDoc(current.trueType);
5534
5686
  if (doc) {
5535
5687
  for (const key of literalKeys(current.extendsType)) {
@@ -5548,10 +5700,10 @@ function serializeResolvedMembers(type, node, ctx) {
5548
5700
  for (const prop of type.getProperties()) {
5549
5701
  const decl = prop.getDeclarations()?.[0] ?? node;
5550
5702
  const rawPropType = checker.getTypeOfSymbolAtLocation(prop, decl);
5551
- const propType = prop.flags & ts12.SymbolFlags.Optional ? stripUndefinedFromType(rawPropType, checker) : rawPropType;
5703
+ const propType = prop.flags & ts13.SymbolFlags.Optional ? stripUndefinedFromType(rawPropType, checker) : rawPropType;
5552
5704
  registerReferencedTypes(propType, ctx);
5553
5705
  const callSigs = propType.getCallSignatures();
5554
- const isMethodDecl = ts12.isMethodSignature(decl) || ts12.isMethodDeclaration(decl) || ts12.isFunctionDeclaration(decl);
5706
+ const isMethodDecl = ts13.isMethodSignature(decl) || ts13.isMethodDeclaration(decl) || ts13.isFunctionDeclaration(decl);
5555
5707
  const kind = callSigs.length > 0 && isMethodDecl ? "method" : "property";
5556
5708
  let { description, tags } = getJSDocComment(decl, prop, checker);
5557
5709
  let { deprecated, reason: deprecationReason } = isSymbolDeprecated(prop);
@@ -5569,11 +5721,11 @@ function serializeResolvedMembers(type, node, ctx) {
5569
5721
  ({ deprecated, reason: deprecationReason } = isSymbolDeprecated(armAlias));
5570
5722
  }
5571
5723
  const flags = {};
5572
- if (prop.flags & ts12.SymbolFlags.Optional)
5724
+ if (prop.flags & ts13.SymbolFlags.Optional)
5573
5725
  flags.optional = true;
5574
5726
  if (isReadonlyPropertySymbol(prop))
5575
5727
  flags.readonly = true;
5576
- if (prop.flags & ts12.SymbolFlags.Method)
5728
+ if (prop.flags & ts13.SymbolFlags.Method)
5577
5729
  flags.methodSyntax = true;
5578
5730
  const schema = kind === "property" ? decoratePropertySchema(buildSchema(propType, checker, ctx, declaredTypeNode(prop.valueDeclaration ?? prop.getDeclarations()?.[0])), prop, propType, checker) : decoratePropertySchema({ "x-ts-function": true }, prop, propType, checker);
5579
5731
  const inlineTags = parseInlineTags(description);
@@ -5592,14 +5744,17 @@ function serializeResolvedMembers(type, node, ctx) {
5592
5744
  return members;
5593
5745
  }
5594
5746
 
5747
+ // src/serializers/variables.ts
5748
+ import ts15 from "typescript";
5749
+
5595
5750
  // src/schema/registry.ts
5596
- import ts13 from "typescript";
5751
+ import ts14 from "typescript";
5597
5752
  function isTypeReference(type) {
5598
- return !!(type.flags & ts13.TypeFlags.Object && type.objectFlags && type.objectFlags & ts13.ObjectFlags.Reference);
5753
+ return !!(type.flags & ts14.TypeFlags.Object && type.objectFlags && type.objectFlags & ts14.ObjectFlags.Reference);
5599
5754
  }
5600
5755
  function getNonNullableType(type) {
5601
5756
  if (type.isUnion()) {
5602
- const nonNullable = type.types.filter((t) => !(t.flags & ts13.TypeFlags.Undefined) && !(t.flags & ts13.TypeFlags.Null));
5757
+ const nonNullable = type.types.filter((t) => !(t.flags & ts14.TypeFlags.Undefined) && !(t.flags & ts14.TypeFlags.Null));
5603
5758
  if (nonNullable.length === 1) {
5604
5759
  return nonNullable[0];
5605
5760
  }
@@ -5762,12 +5917,17 @@ function serializeVariable(node, statement, ctx) {
5762
5917
  const name = symbol?.getName() ?? node.name.getText();
5763
5918
  if (!name)
5764
5919
  return null;
5765
- const { description, tags, examples, source, deprecated, deprecationReason, inlineTags } = extractExportMetadata(node, symbol, ctx.typeChecker, statement);
5766
- const type = ctx.typeChecker.getTypeAtLocation(node);
5920
+ return serializeValue(name, node, symbol, statement, ctx.typeChecker.getTypeAtLocation(node), ts15.isVariableDeclaration(node) ? node.type : undefined, ctx);
5921
+ }
5922
+ function serializeDefaultExpression(node, symbol, type, ctx) {
5923
+ return serializeValue(symbol.getName(), node.expression, symbol, node, type, undefined, ctx);
5924
+ }
5925
+ function serializeValue(name, node, symbol, jsdocNode, type, typeNode, ctx) {
5926
+ const { description, tags, examples, source, deprecated, deprecationReason, inlineTags } = extractExportMetadata(node, symbol, ctx.typeChecker, jsdocNode);
5767
5927
  const schemaExtraction = extractSchemaType(type, ctx.typeChecker);
5768
5928
  const typeToSerialize = schemaExtraction?.outputType ?? type;
5769
5929
  registerReferencedTypes(typeToSerialize, ctx);
5770
- const schema = buildSchema(typeToSerialize, ctx.typeChecker, ctx, node.type);
5930
+ const schema = buildSchema(typeToSerialize, ctx.typeChecker, ctx, typeNode);
5771
5931
  const flags = schemaExtraction ? {
5772
5932
  schemaLibrary: schemaExtraction.adapter.id,
5773
5933
  ...schemaExtraction.inputType && schemaExtraction.inputType !== schemaExtraction.outputType ? { hasTransform: true } : {}
@@ -6353,9 +6513,10 @@ async function getExport(options) {
6353
6513
  }
6354
6514
  const ctx = createContext(program, sourceFile, { maxTypeDepth });
6355
6515
  ctx.exportedIds = exportedIds;
6516
+ claimExportedTypeIds(exportedSymbols, ctx);
6356
6517
  try {
6357
6518
  const originalDecls = targetSymbol.declarations ?? [];
6358
- const isNamespaceExportDecl = originalDecls.some((d) => ts14.isNamespaceExport(d) || ts14.isNamespaceImport(d));
6519
+ const isNamespaceExportDecl = originalDecls.some((d) => ts16.isNamespaceExport(d) || ts16.isNamespaceImport(d));
6359
6520
  if (isNamespaceExportDecl) {
6360
6521
  const spec2 = serializeNamespaceForGet(targetSymbol, exportName, ctx);
6361
6522
  const types2 = ctx.typeRegistry.getAll().map((t) => normalizeType(t));
@@ -6406,42 +6567,42 @@ function resolveExportTarget2(symbol, checker) {
6406
6567
  let isTypeOnly = false;
6407
6568
  const declarations = symbol.declarations ?? [];
6408
6569
  for (const decl of declarations) {
6409
- if (ts14.isExportSpecifier(decl)) {
6570
+ if (ts16.isExportSpecifier(decl)) {
6410
6571
  if (decl.isTypeOnly)
6411
6572
  isTypeOnly = true;
6412
6573
  const exportDecl = decl.parent?.parent;
6413
- if (exportDecl && ts14.isExportDeclaration(exportDecl) && exportDecl.isTypeOnly) {
6574
+ if (exportDecl && ts16.isExportDeclaration(exportDecl) && exportDecl.isTypeOnly) {
6414
6575
  isTypeOnly = true;
6415
6576
  }
6416
6577
  }
6417
6578
  }
6418
- if (symbol.flags & ts14.SymbolFlags.Alias) {
6579
+ if (symbol.flags & ts16.SymbolFlags.Alias) {
6419
6580
  const aliased = checker.getAliasedSymbol(symbol);
6420
6581
  if (aliased && aliased !== symbol) {
6421
6582
  resolvedSymbol2 = aliased;
6422
6583
  }
6423
6584
  }
6424
6585
  const targetDeclarations = resolvedSymbol2.declarations ?? [];
6425
- const declaration = resolvedSymbol2.valueDeclaration || targetDeclarations.find((d) => d.kind !== ts14.SyntaxKind.ExportSpecifier) || targetDeclarations[0];
6586
+ const declaration = resolvedSymbol2.valueDeclaration || targetDeclarations.find((d) => d.kind !== ts16.SyntaxKind.ExportSpecifier) || targetDeclarations[0];
6426
6587
  return { declaration, resolvedSymbol: resolvedSymbol2, isTypeOnly };
6427
6588
  }
6428
6589
  function serializeDeclaration(declaration, _exportSymbol, _targetSymbol, exportName, ctx, isTypeOnly) {
6429
6590
  let result = null;
6430
- if (ts14.isFunctionDeclaration(declaration)) {
6591
+ if (ts16.isFunctionDeclaration(declaration)) {
6431
6592
  result = serializeFunctionExport(declaration, ctx);
6432
- } else if (ts14.isClassDeclaration(declaration)) {
6593
+ } else if (ts16.isClassDeclaration(declaration)) {
6433
6594
  result = serializeClass(declaration, ctx);
6434
- } else if (ts14.isInterfaceDeclaration(declaration)) {
6595
+ } else if (ts16.isInterfaceDeclaration(declaration)) {
6435
6596
  result = serializeInterface(declaration, ctx);
6436
- } else if (ts14.isTypeAliasDeclaration(declaration)) {
6597
+ } else if (ts16.isTypeAliasDeclaration(declaration)) {
6437
6598
  result = serializeTypeAlias(declaration, ctx);
6438
- } else if (ts14.isEnumDeclaration(declaration)) {
6599
+ } else if (ts16.isEnumDeclaration(declaration)) {
6439
6600
  result = serializeEnum(declaration, ctx);
6440
- } else if (ts14.isVariableDeclaration(declaration)) {
6601
+ } else if (ts16.isVariableDeclaration(declaration)) {
6441
6602
  const varStatement = declaration.parent?.parent;
6442
- if (varStatement && ts14.isVariableStatement(varStatement)) {
6443
- if (declaration.initializer && (ts14.isArrowFunction(declaration.initializer) || ts14.isFunctionExpression(declaration.initializer))) {
6444
- const varName = ts14.isIdentifier(declaration.name) ? declaration.name.text : declaration.name.getText();
6603
+ if (varStatement && ts16.isVariableStatement(varStatement)) {
6604
+ if (declaration.initializer && (ts16.isArrowFunction(declaration.initializer) || ts16.isFunctionExpression(declaration.initializer))) {
6605
+ const varName = ts16.isIdentifier(declaration.name) ? declaration.name.text : declaration.name.getText();
6445
6606
  result = serializeFunctionExport(declaration.initializer, ctx, varName);
6446
6607
  } else {
6447
6608
  const checker = ctx.program.getTypeChecker();
@@ -6455,7 +6616,7 @@ function serializeDeclaration(declaration, _exportSymbol, _targetSymbol, exportN
6455
6616
  }
6456
6617
  }
6457
6618
  }
6458
- } else if (ts14.isNamespaceExport(declaration) || ts14.isModuleDeclaration(declaration) || ts14.isNamespaceImport(declaration) || ts14.isSourceFile(declaration)) {
6619
+ } else if (ts16.isNamespaceExport(declaration) || ts16.isModuleDeclaration(declaration) || ts16.isNamespaceImport(declaration) || ts16.isSourceFile(declaration)) {
6459
6620
  result = serializeNamespaceForGet(_exportSymbol, exportName, ctx);
6460
6621
  }
6461
6622
  if (result) {
@@ -6471,7 +6632,7 @@ function serializeDeclaration(declaration, _exportSymbol, _targetSymbol, exportN
6471
6632
  function serializeNamespaceForGet(symbol, exportName, ctx) {
6472
6633
  const checker = ctx.program.getTypeChecker();
6473
6634
  let targetSymbol = symbol;
6474
- if (symbol.flags & ts14.SymbolFlags.Alias) {
6635
+ if (symbol.flags & ts16.SymbolFlags.Alias) {
6475
6636
  const aliased = checker.getAliasedSymbol(symbol);
6476
6637
  if (aliased && aliased !== symbol) {
6477
6638
  targetSymbol = aliased;
@@ -6501,7 +6662,7 @@ function serializeNamespaceForGet(symbol, exportName, ctx) {
6501
6662
  }
6502
6663
  function detectExternalPackage(symbol, checker) {
6503
6664
  let targetSymbol = symbol;
6504
- if (symbol.flags & ts14.SymbolFlags.Alias) {
6665
+ if (symbol.flags & ts16.SymbolFlags.Alias) {
6505
6666
  const aliased = checker.getAliasedSymbol(symbol);
6506
6667
  if (aliased && aliased !== symbol) {
6507
6668
  targetSymbol = aliased;
@@ -6513,9 +6674,9 @@ function detectExternalPackage(symbol, checker) {
6513
6674
  const pkg = sf && packageNameFromPath(sf.fileName);
6514
6675
  if (pkg)
6515
6676
  return pkg;
6516
- if (ts14.isExportSpecifier(decl)) {
6677
+ if (ts16.isExportSpecifier(decl)) {
6517
6678
  const exportDecl = decl.parent?.parent;
6518
- if (exportDecl && ts14.isExportDeclaration(exportDecl) && exportDecl.moduleSpecifier) {
6679
+ if (exportDecl && ts16.isExportDeclaration(exportDecl) && exportDecl.moduleSpecifier) {
6519
6680
  const moduleText = exportDecl.moduleSpecifier.text;
6520
6681
  if (!moduleText.startsWith(".") && !moduleText.startsWith("/")) {
6521
6682
  return moduleText;
@@ -6527,7 +6688,7 @@ function detectExternalPackage(symbol, checker) {
6527
6688
  }
6528
6689
  // src/primitives/list.ts
6529
6690
  import * as path6 from "node:path";
6530
- import ts15 from "typescript";
6691
+ import ts17 from "typescript";
6531
6692
  async function listExports(options) {
6532
6693
  const { entryFile, baseDir, content } = options;
6533
6694
  const errors = [];
@@ -6570,16 +6731,16 @@ async function listExports(options) {
6570
6731
  }
6571
6732
  function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
6572
6733
  const name = symbol.getName();
6573
- const isReexport = !!(symbol.flags & ts15.SymbolFlags.Alias);
6734
+ const isReexport = !!(symbol.flags & ts17.SymbolFlags.Alias);
6574
6735
  let targetSymbol = symbol;
6575
- if (symbol.flags & ts15.SymbolFlags.Alias) {
6736
+ if (symbol.flags & ts17.SymbolFlags.Alias) {
6576
6737
  const aliased = checker.getAliasedSymbol(symbol);
6577
6738
  if (aliased && aliased !== symbol) {
6578
6739
  targetSymbol = aliased;
6579
6740
  }
6580
6741
  }
6581
6742
  const declarations = targetSymbol.declarations ?? [];
6582
- const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !== ts15.SyntaxKind.ExportSpecifier) || declarations[0];
6743
+ const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !== ts17.SyntaxKind.ExportSpecifier) || declarations[0];
6583
6744
  if (!declaration) {
6584
6745
  return {
6585
6746
  name,
@@ -6589,7 +6750,7 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
6589
6750
  reexport: true
6590
6751
  };
6591
6752
  }
6592
- if (ts15.isSourceFile(declaration)) {
6753
+ if (ts17.isSourceFile(declaration)) {
6593
6754
  return {
6594
6755
  name,
6595
6756
  kind: "namespace",
@@ -6631,7 +6792,7 @@ function getDescriptionPreview(symbol, checker) {
6631
6792
  import * as fs7 from "node:fs";
6632
6793
  import * as path10 from "node:path";
6633
6794
  import { SCHEMA_URL, SCHEMA_VERSION } from "@openpkg-ts/spec";
6634
- import ts19 from "typescript";
6795
+ import ts21 from "typescript";
6635
6796
 
6636
6797
  // src/schema/standard-schema.ts
6637
6798
  import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
@@ -7183,7 +7344,7 @@ async function extractStandardSchemasFromProject(entryFile, baseDir, options = {
7183
7344
  import * as fs6 from "node:fs";
7184
7345
  import * as path8 from "node:path";
7185
7346
  import picomatch2 from "picomatch";
7186
- import ts16 from "typescript";
7347
+ import ts18 from "typescript";
7187
7348
  function matchesExternalPattern(packageName, include, exclude) {
7188
7349
  if (!include?.length)
7189
7350
  return false;
@@ -7199,7 +7360,7 @@ function matchesExternalPattern(packageName, include, exclude) {
7199
7360
  return true;
7200
7361
  }
7201
7362
  function resolveExternalModule(moduleSpecifier, containingFile, compilerOptions) {
7202
- const resolved = ts16.resolveModuleName(moduleSpecifier, containingFile, compilerOptions, ts16.sys);
7363
+ const resolved = ts18.resolveModuleName(moduleSpecifier, containingFile, compilerOptions, ts18.sys);
7203
7364
  if (!resolved.resolvedModule) {
7204
7365
  return null;
7205
7366
  }
@@ -7264,7 +7425,7 @@ function extractExternalExport(exportName, resolvedModule, program, ctx, visited
7264
7425
  return null;
7265
7426
  }
7266
7427
  let resolvedSymbol2 = targetExport;
7267
- if (targetExport.flags & ts16.SymbolFlags.Alias) {
7428
+ if (targetExport.flags & ts18.SymbolFlags.Alias) {
7268
7429
  const aliased = checker.getAliasedSymbol(targetExport);
7269
7430
  if (aliased && aliased !== targetExport) {
7270
7431
  resolvedSymbol2 = aliased;
@@ -7335,7 +7496,7 @@ function mergeRuntimeSchemas(staticExports, runtimeSchemas) {
7335
7496
  }
7336
7497
 
7337
7498
  // src/builder/type-cache.ts
7338
- import ts17 from "typescript";
7499
+ import ts19 from "typescript";
7339
7500
 
7340
7501
  // src/utils/cache-manager.ts
7341
7502
  class CacheManager {
@@ -7442,10 +7603,10 @@ function findTypeDefinition(typeName, program, sourceFile) {
7442
7603
  return typeDefinitionCache.getOrCompute(typeName, () => {
7443
7604
  const checker = program.getTypeChecker();
7444
7605
  const findInNode = (node) => {
7445
- if ((ts17.isInterfaceDeclaration(node) || ts17.isTypeAliasDeclaration(node) || ts17.isClassDeclaration(node) || ts17.isEnumDeclaration(node)) && node.name?.text === typeName) {
7606
+ if ((ts19.isInterfaceDeclaration(node) || ts19.isTypeAliasDeclaration(node) || ts19.isClassDeclaration(node) || ts19.isEnumDeclaration(node)) && node.name?.text === typeName) {
7446
7607
  return node.getSourceFile().fileName;
7447
7608
  }
7448
- return ts17.forEachChild(node, findInNode);
7609
+ return ts19.forEachChild(node, findInNode);
7449
7610
  };
7450
7611
  const entryResult = findInNode(sourceFile);
7451
7612
  if (entryResult)
@@ -7457,14 +7618,14 @@ function findTypeDefinition(typeName, program, sourceFile) {
7457
7618
  return result;
7458
7619
  }
7459
7620
  }
7460
- const symbol = checker.resolveName(typeName, sourceFile, ts17.SymbolFlags.Type, false);
7621
+ const symbol = checker.resolveName(typeName, sourceFile, ts19.SymbolFlags.Type, false);
7461
7622
  return symbol?.declarations?.[0]?.getSourceFile().fileName;
7462
7623
  });
7463
7624
  }
7464
7625
  function hasInternalTag(typeName, program, sourceFile) {
7465
7626
  return internalTagCache.getOrCompute(typeName, () => {
7466
7627
  const checker = program.getTypeChecker();
7467
- const symbol = checker.resolveName(typeName, sourceFile, ts17.SymbolFlags.Type, false);
7628
+ const symbol = checker.resolveName(typeName, sourceFile, ts19.SymbolFlags.Type, false);
7468
7629
  if (!symbol)
7469
7630
  return false;
7470
7631
  return symbol.getJsDocTags().some((tag) => tag.name === "internal");
@@ -7472,7 +7633,7 @@ function hasInternalTag(typeName, program, sourceFile) {
7472
7633
  }
7473
7634
 
7474
7635
  // src/builder/type-expansion.ts
7475
- import ts18 from "typescript";
7636
+ import ts20 from "typescript";
7476
7637
  function createExternalExpansionPredicate(opts) {
7477
7638
  const matchesEntry = (entry, pkg) => {
7478
7639
  if (!entry.includes("*"))
@@ -7526,7 +7687,7 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7526
7687
  const symbol = type.aliasSymbol ?? type.getSymbol();
7527
7688
  const named = !!symbol && !symbol.getName().startsWith("__");
7528
7689
  const allowed = !named || !symbol || symbolAllowed(symbol);
7529
- if (named && allowed && symbol && !ctx.exportedIds.has(symbol.getName())) {
7690
+ if (named && allowed && symbol && !isExportedType(symbol)) {
7530
7691
  ctx.typeRegistry.registerType(type, ctx);
7531
7692
  const name = symbol.getName();
7532
7693
  if (!symbolByName.has(name)) {
@@ -7547,7 +7708,7 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7547
7708
  visit(t, depth + 1);
7548
7709
  }
7549
7710
  }
7550
- if (!allowed || isDeferredMappedOrConditional(type) || !(type.flags & ts18.TypeFlags.Object || type.isClassOrInterface())) {
7711
+ if (!allowed || isDeferredMappedOrConditional(type) || !(type.flags & ts20.TypeFlags.Object || type.isClassOrInterface())) {
7551
7712
  return;
7552
7713
  }
7553
7714
  if (isForeignPackage(symbol, opts.workspacePackages)) {
@@ -7573,14 +7734,20 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7573
7734
  visit(info.type, depth + 1);
7574
7735
  }
7575
7736
  };
7576
- const TYPE_SYMBOL_FLAGS = ts18.SymbolFlags.Interface | ts18.SymbolFlags.TypeAlias | ts18.SymbolFlags.Class | ts18.SymbolFlags.RegularEnum | ts18.SymbolFlags.ConstEnum;
7737
+ const TYPE_SYMBOL_FLAGS = ts20.SymbolFlags.Interface | ts20.SymbolFlags.TypeAlias | ts20.SymbolFlags.Class | ts20.SymbolFlags.RegularEnum | ts20.SymbolFlags.ConstEnum;
7738
+ const isExportedType = (symbol) => {
7739
+ const name = symbol.getName();
7740
+ if (!ctx.exportedIds.has(name))
7741
+ return false;
7742
+ return !(symbol.flags & TYPE_SYMBOL_FLAGS) || resolveTypeId(symbol, ctx) === name;
7743
+ };
7577
7744
  const visitedSymbols = new Set;
7578
7745
  const symbolKind = (symbol) => {
7579
- if (symbol.flags & ts18.SymbolFlags.Interface)
7746
+ if (symbol.flags & ts20.SymbolFlags.Interface)
7580
7747
  return "interface";
7581
- if (symbol.flags & ts18.SymbolFlags.Class)
7748
+ if (symbol.flags & ts20.SymbolFlags.Class)
7582
7749
  return "class";
7583
- if (symbol.flags & (ts18.SymbolFlags.RegularEnum | ts18.SymbolFlags.ConstEnum))
7750
+ if (symbol.flags & (ts20.SymbolFlags.RegularEnum | ts20.SymbolFlags.ConstEnum))
7584
7751
  return "enum";
7585
7752
  return "type";
7586
7753
  };
@@ -7588,6 +7755,7 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7588
7755
  const resolved = resolveAliasSymbol(symbol, checker, undefined, ctx.program);
7589
7756
  return resolved;
7590
7757
  };
7758
+ const writtenWhenAny = (symbol, declared) => declared.flags & ts20.TypeFlags.Any ? symbol.declarations?.find(ts20.isTypeAliasDeclaration)?.type : undefined;
7591
7759
  const symbolByName = new Map;
7592
7760
  const registerTypeSymbol = (symbol) => {
7593
7761
  const name = symbol.getName();
@@ -7597,7 +7765,7 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7597
7765
  return;
7598
7766
  if (!symbolAllowed(symbol))
7599
7767
  return;
7600
- if (ctx.exportedIds.has(name)) {
7768
+ if (isExportedType(symbol)) {
7601
7769
  walkDeclarations(symbol);
7602
7770
  return;
7603
7771
  }
@@ -7613,7 +7781,7 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7613
7781
  id,
7614
7782
  name,
7615
7783
  kind: symbolKind(symbol),
7616
- schema: ensureNonEmptySchema(buildSchema(declared, checker, ctx), declared, checker)
7784
+ schema: ensureNonEmptySchema(buildSchema(declared, checker, ctx, writtenWhenAny(symbol, declared)), declared, checker)
7617
7785
  });
7618
7786
  }
7619
7787
  symbolByName.set(name, symbol);
@@ -7631,7 +7799,7 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7631
7799
  const target = symbol && resolveAlias(symbol);
7632
7800
  if (!target || visitedSymbols.has(target))
7633
7801
  return;
7634
- if (!(target.flags & (ts18.SymbolFlags.ValueModule | ts18.SymbolFlags.NamespaceModule)))
7802
+ if (!(target.flags & (ts20.SymbolFlags.ValueModule | ts20.SymbolFlags.NamespaceModule)))
7635
7803
  return;
7636
7804
  if (!symbolAllowed(target))
7637
7805
  return;
@@ -7648,22 +7816,22 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7648
7816
  }
7649
7817
  };
7650
7818
  const walkNode = (node) => {
7651
- if (ts18.isTypeReferenceNode(node)) {
7819
+ if (ts20.isTypeReferenceNode(node)) {
7652
7820
  handleRef(node.typeName);
7653
- if (ts18.isQualifiedName(node.typeName)) {
7821
+ if (ts20.isQualifiedName(node.typeName)) {
7654
7822
  handleNamespaceRef(node.typeName.left);
7655
7823
  }
7656
- } else if (ts18.isExpressionWithTypeArguments(node)) {
7824
+ } else if (ts20.isExpressionWithTypeArguments(node)) {
7657
7825
  handleRef(node.expression);
7658
- } else if (ts18.isTypeQueryNode(node)) {
7826
+ } else if (ts20.isTypeQueryNode(node)) {
7659
7827
  handleRef(node.exprName);
7660
- if (ts18.isQualifiedName(node.exprName)) {
7828
+ if (ts20.isQualifiedName(node.exprName)) {
7661
7829
  handleRef(node.exprName.left);
7662
7830
  handleNamespaceRef(node.exprName.left);
7663
7831
  }
7664
- } else if (ts18.isImportTypeNode(node) && node.qualifier) {
7832
+ } else if (ts20.isImportTypeNode(node) && node.qualifier) {
7665
7833
  handleRef(node.qualifier);
7666
- if (ts18.isQualifiedName(node.qualifier)) {
7834
+ if (ts20.isQualifiedName(node.qualifier)) {
7667
7835
  handleNamespaceRef(node.qualifier.left);
7668
7836
  }
7669
7837
  }
@@ -7679,7 +7847,7 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7679
7847
  };
7680
7848
  for (const exportSymbol of exportedSymbols) {
7681
7849
  let target = exportSymbol;
7682
- if (exportSymbol.flags & ts18.SymbolFlags.Alias) {
7850
+ if (exportSymbol.flags & ts20.SymbolFlags.Alias) {
7683
7851
  try {
7684
7852
  target = checker.getAliasedSymbol(exportSymbol);
7685
7853
  } catch {
@@ -7979,6 +8147,7 @@ async function extract(options) {
7979
8147
  ...included ? {} : { skipReason: "filtered" }
7980
8148
  });
7981
8149
  }
8150
+ const mergedTypeSides = [];
7982
8151
  const followExternal = options.followExternal;
7983
8152
  const ctx = createContext(program, sourceFile, {
7984
8153
  maxTypeDepth,
@@ -7994,6 +8163,7 @@ async function extract(options) {
7994
8163
  workspacePackages: result.workspacePackages ?? new Map
7995
8164
  });
7996
8165
  ctx.exportedIds = exportedIds;
8166
+ claimExportedTypeIds(exportedSymbols, ctx);
7997
8167
  const filteredSymbols = exportedSymbols.filter((s) => shouldIncludeExport(s.getName(), only, ignore));
7998
8168
  const total = filteredSymbols.length;
7999
8169
  for (let i = 0;i < filteredSymbols.length; i++) {
@@ -8018,9 +8188,9 @@ async function extract(options) {
8018
8188
  externalPackage = pkg;
8019
8189
  break;
8020
8190
  }
8021
- if (ts19.isExportSpecifier(decl)) {
8191
+ if (ts21.isExportSpecifier(decl)) {
8022
8192
  const exportDecl = decl.parent?.parent;
8023
- if (exportDecl && ts19.isExportDeclaration(exportDecl) && exportDecl.moduleSpecifier) {
8193
+ if (exportDecl && ts21.isExportDeclaration(exportDecl) && exportDecl.moduleSpecifier) {
8024
8194
  const moduleText = exportDecl.moduleSpecifier.getText().slice(1, -1);
8025
8195
  if (!moduleText.startsWith(".") && !moduleText.startsWith("/")) {
8026
8196
  externalPackage = moduleText;
@@ -8063,6 +8233,14 @@ async function extract(options) {
8063
8233
  }
8064
8234
  const exp = serializeDeclaration2(declaration, symbol, exportName, ctx, isTypeOnly);
8065
8235
  if (exp) {
8236
+ const typeSide = mergedTypeSideOf(exp, declaration, targetSymbol, ctx);
8237
+ if (typeSide) {
8238
+ mergedTypeSides.push({
8239
+ index: exports.length,
8240
+ symbol: typeSide,
8241
+ ontoClass: ts21.isClassDeclaration(declaration)
8242
+ });
8243
+ }
8066
8244
  exports.push(exp);
8067
8245
  tracker.status = "success";
8068
8246
  tracker.kind = exp.kind;
@@ -8081,6 +8259,9 @@ async function extract(options) {
8081
8259
  });
8082
8260
  }
8083
8261
  }
8262
+ for (const { index, symbol, ontoClass } of mergedTypeSides) {
8263
+ exports[index] = withMergedTypeSide(exports[index], symbol, ctx, ontoClass);
8264
+ }
8084
8265
  const verification = buildVerificationSummary(exportedSymbols.length, exports.length, exportTracker);
8085
8266
  const meta = await getPackageMeta(entryFile, baseDir);
8086
8267
  expandReachableTypes(filteredSymbols, ctx, {
@@ -8096,7 +8277,7 @@ async function extract(options) {
8096
8277
  });
8097
8278
  }
8098
8279
  {
8099
- const symFlags = ts19.SymbolFlags.Type | ts19.SymbolFlags.Interface | ts19.SymbolFlags.Class;
8280
+ const symFlags = ts21.SymbolFlags.Type | ts21.SymbolFlags.Interface | ts21.SymbolFlags.Class;
8100
8281
  const maxPasses = 5;
8101
8282
  for (let pass = 0;pass < maxPasses; pass++) {
8102
8283
  const allRefs = new Map;
@@ -8242,42 +8423,39 @@ async function extract(options) {
8242
8423
  }
8243
8424
  function serializeDeclaration2(declaration, exportSymbol, exportName, ctx, isTypeOnly = false) {
8244
8425
  let result = null;
8245
- if (ts19.isFunctionDeclaration(declaration)) {
8426
+ if (ts21.isFunctionDeclaration(declaration)) {
8246
8427
  result = serializeFunctionExport(declaration, ctx);
8247
- } else if (ts19.isClassDeclaration(declaration)) {
8428
+ } else if (ts21.isClassDeclaration(declaration)) {
8248
8429
  result = serializeClass(declaration, ctx);
8249
- } else if (ts19.isInterfaceDeclaration(declaration)) {
8430
+ } else if (ts21.isInterfaceDeclaration(declaration)) {
8250
8431
  result = serializeInterface(declaration, ctx);
8251
- } else if (ts19.isTypeAliasDeclaration(declaration)) {
8432
+ } else if (ts21.isTypeAliasDeclaration(declaration)) {
8252
8433
  result = serializeTypeAlias(declaration, ctx);
8253
- } else if (ts19.isEnumDeclaration(declaration)) {
8434
+ } else if (ts21.isEnumDeclaration(declaration)) {
8254
8435
  result = serializeEnum(declaration, ctx);
8255
- } else if (ts19.isVariableDeclaration(declaration)) {
8256
- const varStatement = declaration.parent?.parent;
8257
- if (varStatement && ts19.isVariableStatement(varStatement)) {
8258
- if (declaration.initializer && (ts19.isArrowFunction(declaration.initializer) || ts19.isFunctionExpression(declaration.initializer))) {
8259
- const varName = ts19.isIdentifier(declaration.name) ? declaration.name.text : declaration.name.getText();
8260
- result = serializeFunctionExport(declaration.initializer, ctx, varName);
8436
+ } else if (ts21.isVariableDeclaration(declaration) || ts21.isBindingElement(declaration)) {
8437
+ const varStatement = variableStatementOf(declaration);
8438
+ if (varStatement) {
8439
+ if (ts21.isVariableDeclaration(declaration) && declaration.initializer && (ts21.isArrowFunction(declaration.initializer) || ts21.isFunctionExpression(declaration.initializer))) {
8440
+ const varName = ts21.isIdentifier(declaration.name) ? declaration.name.text : declaration.name.getText();
8441
+ result = serializeFunctionExport(declaration.initializer, ctx, varName, declaration.type);
8261
8442
  } else {
8262
8443
  result = serializeVariable(declaration, varStatement, ctx);
8263
8444
  if (result?.kind === "variable") {
8264
8445
  const type = ctx.typeChecker.getTypeAtLocation(declaration);
8265
- if (type.getConstructSignatures().length > 0) {
8266
- result = { ...result, kind: "class" };
8267
- } else {
8268
- const callSigs = callSignaturesForVariable(declaration, ctx);
8269
- if (callSigs.length > 0) {
8270
- result = {
8271
- ...result,
8272
- kind: "function",
8273
- signatures: buildSignatures(callSigs, ctx.typeChecker, ctx)
8274
- };
8275
- }
8276
- }
8446
+ result = withCallableKind(result, type, callSignaturesForVariable(declaration, ctx), ctx);
8277
8447
  }
8278
8448
  }
8279
8449
  }
8280
- } else if (ts19.isNamespaceExport(declaration) || ts19.isModuleDeclaration(declaration) || ts19.isNamespaceImport(declaration) || ts19.isSourceFile(declaration)) {
8450
+ } else if (ts21.isExportAssignment(declaration) && !declaration.isExportEquals) {
8451
+ const expression = skipOuterExpressions(declaration.expression);
8452
+ if (ts21.isArrowFunction(expression) || ts21.isFunctionExpression(expression)) {
8453
+ result = serializeFunctionExport(expression, ctx, exportName, undefined, declaration);
8454
+ } else {
8455
+ const type = ctx.typeChecker.getTypeOfSymbol(exportSymbol);
8456
+ result = withCallableKind(serializeDefaultExpression(declaration, exportSymbol, type, ctx), type, type.getCallSignatures(), ctx);
8457
+ }
8458
+ } else if (ts21.isNamespaceExport(declaration) || ts21.isModuleDeclaration(declaration) || ts21.isNamespaceImport(declaration) || ts21.isSourceFile(declaration)) {
8281
8459
  try {
8282
8460
  result = serializeNamespaceExport(exportSymbol, exportName, ctx);
8283
8461
  } catch {
@@ -8293,6 +8471,9 @@ function serializeDeclaration2(declaration, exportSymbol, exportName, ctx, isTyp
8293
8471
  }
8294
8472
  if (result) {
8295
8473
  result = withExportName(result, exportName);
8474
+ const localName = exportName === "default" && defaultLocalName(declaration, exportSymbol);
8475
+ if (localName)
8476
+ result = { ...result, localName };
8296
8477
  if (isTypeOnly) {
8297
8478
  result = {
8298
8479
  ...result,
@@ -8314,7 +8495,7 @@ function serializeNamespaceExport(symbol, exportName, ctx) {
8314
8495
  const members = [];
8315
8496
  const checker = ctx.program.getTypeChecker();
8316
8497
  let targetSymbol = symbol;
8317
- if (symbol.flags & ts19.SymbolFlags.Alias) {
8498
+ if (symbol.flags & ts21.SymbolFlags.Alias) {
8318
8499
  const aliased = checker.getAliasedSymbol(symbol);
8319
8500
  if (aliased && aliased !== symbol) {
8320
8501
  targetSymbol = aliased;
@@ -8342,31 +8523,31 @@ function serializeNamespaceExport(symbol, exportName, ctx) {
8342
8523
  function serializeNamespaceMember(symbol, memberName, ctx) {
8343
8524
  const checker = ctx.program.getTypeChecker();
8344
8525
  let targetSymbol = symbol;
8345
- if (symbol.flags & ts19.SymbolFlags.Alias) {
8526
+ if (symbol.flags & ts21.SymbolFlags.Alias) {
8346
8527
  const aliased = checker.getAliasedSymbol(symbol);
8347
8528
  if (aliased && aliased !== symbol) {
8348
8529
  targetSymbol = aliased;
8349
8530
  }
8350
8531
  }
8351
8532
  const declarations = targetSymbol.declarations ?? [];
8352
- const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !== ts19.SyntaxKind.ExportSpecifier) || declarations[0];
8533
+ const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !== ts21.SyntaxKind.ExportSpecifier) || declarations[0];
8353
8534
  if (!declaration)
8354
8535
  return null;
8355
8536
  const type = checker.getTypeAtLocation(declaration);
8356
8537
  const callSignatures = type.getCallSignatures();
8357
8538
  const { deprecated } = isSymbolDeprecated(targetSymbol);
8358
8539
  let kind = "variable";
8359
- if (ts19.isFunctionDeclaration(declaration) || ts19.isFunctionExpression(declaration)) {
8540
+ if (ts21.isFunctionDeclaration(declaration) || ts21.isFunctionExpression(declaration)) {
8360
8541
  kind = "function";
8361
- } else if (ts19.isClassDeclaration(declaration)) {
8542
+ } else if (ts21.isClassDeclaration(declaration)) {
8362
8543
  kind = "class";
8363
- } else if (ts19.isInterfaceDeclaration(declaration)) {
8544
+ } else if (ts21.isInterfaceDeclaration(declaration)) {
8364
8545
  kind = "interface";
8365
- } else if (ts19.isTypeAliasDeclaration(declaration)) {
8546
+ } else if (ts21.isTypeAliasDeclaration(declaration)) {
8366
8547
  kind = "type";
8367
- } else if (ts19.isEnumDeclaration(declaration)) {
8548
+ } else if (ts21.isEnumDeclaration(declaration)) {
8368
8549
  kind = "enum";
8369
- } else if (ts19.isVariableDeclaration(declaration)) {
8550
+ } else if (ts21.isVariableDeclaration(declaration)) {
8370
8551
  if (callSignatures.length > 0) {
8371
8552
  kind = "function";
8372
8553
  }
@@ -8397,18 +8578,18 @@ function serializeNamespaceMember(symbol, memberName, ctx) {
8397
8578
  function flattenJSDocComment(comment) {
8398
8579
  if (comment === undefined)
8399
8580
  return "";
8400
- return typeof comment === "string" ? comment : ts19.getTextOfJSDocComment(comment) ?? "";
8581
+ return typeof comment === "string" ? comment : ts21.getTextOfJSDocComment(comment) ?? "";
8401
8582
  }
8402
8583
  function getJSDocFromExportSymbol(symbol) {
8403
8584
  const tags = [];
8404
8585
  const examples = [];
8405
8586
  const decl = symbol.declarations?.[0];
8406
8587
  if (decl) {
8407
- const exportDecl = ts19.isNamespaceExport(decl) ? decl.parent : decl;
8408
- if (exportDecl && ts19.isExportDeclaration(exportDecl)) {
8409
- const jsDocs = ts19.getJSDocCommentsAndTags(exportDecl);
8588
+ const exportDecl = ts21.isNamespaceExport(decl) ? decl.parent : decl;
8589
+ if (exportDecl && ts21.isExportDeclaration(exportDecl)) {
8590
+ const jsDocs = ts21.getJSDocCommentsAndTags(exportDecl);
8410
8591
  for (const doc of jsDocs) {
8411
- if (ts19.isJSDoc(doc) && doc.comment) {
8592
+ if (ts21.isJSDoc(doc) && doc.comment) {
8412
8593
  const commentText = flattenJSDocComment(doc.comment);
8413
8594
  if (commentText) {
8414
8595
  return {
@@ -8457,14 +8638,45 @@ function extractExamples(doc) {
8457
8638
  }
8458
8639
  return examples;
8459
8640
  }
8641
+ function variableStatementOf(declaration) {
8642
+ let node = declaration;
8643
+ while (ts21.isBindingElement(node) || ts21.isBindingName(node))
8644
+ node = node.parent;
8645
+ const statement = node.parent?.parent;
8646
+ return statement && ts21.isVariableStatement(statement) ? statement : undefined;
8647
+ }
8648
+ function skipOuterExpressions(expression) {
8649
+ let node = expression;
8650
+ while (ts21.isParenthesizedExpression(node) || ts21.isAsExpression(node) || ts21.isSatisfiesExpression(node) || ts21.isTypeAssertionExpression(node) || ts21.isNonNullExpression(node)) {
8651
+ node = node.expression;
8652
+ }
8653
+ return node;
8654
+ }
8655
+ function withCallableKind(entry, type, callSigs, ctx) {
8656
+ const constructSigs = type.getConstructSignatures();
8657
+ if (constructSigs.length > 0) {
8658
+ return {
8659
+ ...entry,
8660
+ kind: "class",
8661
+ signatures: serializeConstructSignatures(constructSigs, ctx)
8662
+ };
8663
+ }
8664
+ if (callSigs.length === 0)
8665
+ return entry;
8666
+ return {
8667
+ ...entry,
8668
+ kind: "function",
8669
+ signatures: buildSignatures(callSigs, ctx.typeChecker, ctx)
8670
+ };
8671
+ }
8460
8672
  function callSignaturesForVariable(declaration, ctx) {
8461
8673
  const checker = ctx.typeChecker;
8462
- if (declaration.type && ts19.isTypeReferenceNode(declaration.type)) {
8463
- const nameNode = ts19.isQualifiedName(declaration.type.typeName) ? declaration.type.typeName.right : declaration.type.typeName;
8674
+ if (ts21.isVariableDeclaration(declaration) && declaration.type && ts21.isTypeReferenceNode(declaration.type)) {
8675
+ const nameNode = ts21.isQualifiedName(declaration.type.typeName) ? declaration.type.typeName.right : declaration.type.typeName;
8464
8676
  const raw = checker.getSymbolAtLocation(nameNode);
8465
8677
  if (raw) {
8466
8678
  const symbol = resolveAliasSymbol(raw, checker, undefined, ctx.program);
8467
- const iface = symbol.declarations?.find((d) => ts19.isInterfaceDeclaration(d));
8679
+ const iface = symbol.declarations?.find((d) => ts21.isInterfaceDeclaration(d));
8468
8680
  try {
8469
8681
  const declared = checker.getDeclaredTypeOfSymbol(symbol);
8470
8682
  const sigs = declared.getCallSignatures();
@@ -8486,6 +8698,59 @@ function callSignaturesForVariable(declaration, ctx) {
8486
8698
  }
8487
8699
  return checker.getTypeAtLocation(declaration).getCallSignatures();
8488
8700
  }
8701
+ function defaultLocalName(declaration, exportSymbol) {
8702
+ const declared = ts21.getNameOfDeclaration(declaration);
8703
+ if (declared && ts21.isIdentifier(declared) && declared.text !== "default")
8704
+ return declared.text;
8705
+ for (const decl of exportSymbol.declarations ?? []) {
8706
+ if (ts21.isExportAssignment(decl) && ts21.isIdentifier(decl.expression)) {
8707
+ return decl.expression.text;
8708
+ }
8709
+ if (ts21.isExportSpecifier(decl) && decl.propertyName && ts21.isIdentifier(decl.propertyName)) {
8710
+ if (decl.propertyName.text !== "default")
8711
+ return decl.propertyName.text;
8712
+ }
8713
+ }
8714
+ return;
8715
+ }
8716
+ function isValueDeclaration(declaration) {
8717
+ return ts21.isVariableDeclaration(declaration) || ts21.isBindingElement(declaration) || ts21.isFunctionDeclaration(declaration);
8718
+ }
8719
+ function hasTypeSide(symbol) {
8720
+ return (symbol.flags & (ts21.SymbolFlags.Interface | ts21.SymbolFlags.TypeAlias)) !== 0;
8721
+ }
8722
+ function mergedTypeSideOf(exp, declaration, symbol, ctx) {
8723
+ if (ts21.isClassDeclaration(declaration)) {
8724
+ return symbol.flags & ts21.SymbolFlags.Interface ? symbol : undefined;
8725
+ }
8726
+ if (exp.members || !isValueDeclaration(declaration))
8727
+ return;
8728
+ if (hasTypeSide(symbol))
8729
+ return symbol;
8730
+ if (exp.kind !== "class")
8731
+ return;
8732
+ const [construct] = ctx.typeChecker.getTypeAtLocation(declaration).getConstructSignatures();
8733
+ const instance = construct?.getReturnType();
8734
+ const constructed = instance && (instance.aliasSymbol ?? instance.getSymbol());
8735
+ if (!constructed || !hasTypeSide(constructed))
8736
+ return;
8737
+ if (ctx.shouldExpandExternal && !ctx.shouldExpandExternal(constructed))
8738
+ return;
8739
+ return constructed;
8740
+ }
8741
+ function withMergedTypeSide(entry, symbol, ctx, ontoClass) {
8742
+ const typeSide = serializeMergedTypeSide(symbol, ctx);
8743
+ if (!typeSide)
8744
+ return entry;
8745
+ const { members, description, tags, ...instanceType } = typeSide;
8746
+ const own = new Set(entry.members?.map((m) => m.name));
8747
+ return {
8748
+ ...entry,
8749
+ members: [...entry.members ?? [], ...(members ?? []).filter((m) => !own.has(m.name))],
8750
+ ...entry.kind === "class" && !ontoClass ? instanceType : {},
8751
+ ...entry.description ? {} : { description, tags: [...entry.tags ?? [], ...tags ?? []] }
8752
+ };
8753
+ }
8489
8754
  function withExportName(entry, exportName) {
8490
8755
  if (entry.name === exportName) {
8491
8756
  return entry;
@@ -9002,7 +9267,7 @@ function toToolSchema(exp, spec, options) {
9002
9267
  const required = [];
9003
9268
  for (const param of sig.parameters ?? []) {
9004
9269
  let paramSchema = normalizeSchema(param.schema);
9005
- if (param.rest) {
9270
+ if (param.rest && paramSchema.type !== "array") {
9006
9271
  paramSchema = { type: "array", items: paramSchema };
9007
9272
  }
9008
9273
  if (param.description && !paramSchema.description) {
@@ -9040,12 +9305,12 @@ function toToolSchema(exp, spec, options) {
9040
9305
  };
9041
9306
  }
9042
9307
  // src/types/utils.ts
9043
- import ts20 from "typescript";
9308
+ import ts22 from "typescript";
9044
9309
  function isExported(node) {
9045
9310
  const modifiers = node.modifiers;
9046
9311
  if (!modifiers)
9047
9312
  return false;
9048
- return modifiers.some((m) => m.kind === ts20.SyntaxKind.ExportKeyword);
9313
+ return modifiers.some((m) => m.kind === ts22.SyntaxKind.ExportKeyword);
9049
9314
  }
9050
9315
  function getNodeName(node) {
9051
9316
  if ("name" in node && node.name) {