Skip to content

Commit de7189d

Browse files
committed
Fix
1 parent a8a217e commit de7189d

3 files changed

Lines changed: 40 additions & 7 deletions

File tree

README.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,12 +647,14 @@ Version History
647647

648648
5.0.0: (Unreleased)
649649
* Droped support for Python 3.9 (pyodide/sphinx-js-fork#7)
650-
* Dropped support for typedoc 0.15, added support for typedoc 0.25, 0.26, and
651-
0.27 (pyodide/sphinx-js-fork#11, pyodide/sphinx-js-fork#22,
650+
* Dropped support for typedoc 0.15, added support for typedoc 0.25--0.28
651+
(pyodide/sphinx-js-fork#11, pyodide/sphinx-js-fork#22,
652652
pyodide/sphinx-js-fork#31, pyodide/sphinx-js-fork#39,
653653
pyodide/sphinx-js-fork#41, pyodide/sphinx-js-fork#43
654654
pyodide/sphinx-js-fork#52, pyodide/sphinx-js-fork#53,
655-
pyodide/sphinx-js-fork#54, pyodide/sphinx-js-fork#174)
655+
pyodide/sphinx-js-fork#54, pyodide/sphinx-js-fork#174,
656+
#266
657+
)
656658
* Added handling for Typescript type parameters and type bounds.
657659
(pyodide/sphinx-js-fork#25)
658660
* Only monkeypatch Sphinx classes when sphinx_js extension is used

sphinx_js/js/convertTopLevel.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212
TypeContext,
1313
TypeParameterReflection,
1414
} from "typedoc";
15-
import { referenceToXRef, convertType } from "./convertType.ts";
15+
import {
16+
referenceToXRef,
17+
convertType,
18+
convertTypeLiteral,
19+
} from "./convertType.ts";
1620
import {
1721
NO_DEFAULT,
1822
Attribute,
@@ -878,10 +882,23 @@ export class Converter {
878882
}
879883

880884
convertTypeAlias(ty: DeclarationReflection): ConvertResult {
885+
let type;
886+
if (ty.type) {
887+
type = this.convertType(ty.type);
888+
} else {
889+
// Handle this change:
890+
// https://github.com/TypeStrong/typedoc/commit/ca94f7eaecf90c25d6377e20c405626817de1e26#diff-14759d25b74ca53aee4558d0e26c85eee3c13484ea3ccdf28872b906829ef6f8R380-R390
891+
type = convertTypeLiteral(
892+
this.basePath,
893+
this.pathMap,
894+
this.symbolToType,
895+
ty,
896+
);
897+
}
881898
const ir: TopLevelIR = {
882899
...this.topLevelProperties(ty),
883900
kind: "typeAlias",
884-
type: this.convertType(ty.type!),
901+
type,
885902
type_params: this.typeParamsToIR(ty.typeParameters),
886903
};
887904
return [ir, ty.children];

sphinx_js/js/convertType.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class TypeConverter implements TypeVisitor<Type> {
215215
// up so in this case we index on file name and reference name.
216216

217217
// Another place where we incorrectly handle merged declarations
218-
const src = type.reflection?.sources?.[0];
218+
const src = refl?.sources?.[0];
219219
if (!src) {
220220
return undefined;
221221
}
@@ -281,7 +281,7 @@ class TypeConverter implements TypeVisitor<Type> {
281281
throw new Error("This shouldn't happen");
282282
}
283283

284-
const path = parseFilePath(type.symbolId.fileName, this.basePath);
284+
const path = parseFilePath(type.symbolId?.fileName ?? "", this.basePath);
285285
if (path.includes("node_modules/")) {
286286
// External reference
287287
const xref: TypeXRefExternal = {
@@ -420,6 +420,7 @@ class TypeConverter implements TypeVisitor<Type> {
420420
}
421421
const result: Type = ["{ "];
422422
// lit.indexSignature for 0.25.x, lit.indexSignatures for 0.26.0 and later.
423+
// @ts-ignore
423424
const index_sig = lit.indexSignature ?? lit.indexSignatures?.[0];
424425
if (index_sig) {
425426
if (index_sig.parameters?.length !== 1) {
@@ -472,6 +473,19 @@ export function convertType(
472473
return typeConverter.convert(type, context);
473474
}
474475

476+
export function convertTypeLiteral(
477+
basePath: string,
478+
reflToPath: ReadonlyMap<
479+
DeclarationReflection | SignatureReflection,
480+
string[]
481+
>,
482+
symbolToType: ReadonlySymbolToType,
483+
type: DeclarationReflection,
484+
): Type {
485+
const typeConverter = new TypeConverter(basePath, reflToPath, symbolToType);
486+
return typeConverter.convertTypeLiteral(type);
487+
}
488+
475489
export function referenceToXRef(
476490
basePath: string,
477491
reflToPath: ReadonlyMap<

0 commit comments

Comments
 (0)