Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle self referential function types without crashing #58

Merged
merged 1 commit into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion sphinx_js/typedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,11 @@ def inner(param: Param) -> Iterator[str | ir.TypeXRef]:
yield from riffle((inner(param) for param in self.parameters), ", ")

yield "): "
ret = self.return_type(converter)[0].type
return_type = self.return_type(converter)
if return_type:
ret = return_type[0].type
else:
ret = "void"
assert ret
if isinstance(ret, str):
yield ret
Expand Down Expand Up @@ -1062,6 +1066,14 @@ def _render_name_root(self, converter: Converter) -> Iterator[str | ir.TypeXRef]
yield "<TODO: not implemented>"


class UnknownType(TypeBase):
type: Literal["unknown"]
name: str

def _render_name_root(self, converter: Converter) -> Iterator[str | ir.TypeXRef]:
yield self.name


AnyNode = Node | Project | Signature


Expand All @@ -1075,6 +1087,7 @@ def _render_name_root(self, converter: Converter) -> Iterator[str | ir.TypeXRef]
| ReferenceType
| ReflectionType
| TupleType
| UnknownType
)

TypeD = Annotated[Type, Field(discriminator="type")]
Expand Down
6 changes: 6 additions & 0 deletions tests/test_build_ts/source/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ export function blah(a: OptionalThings) : ConstructorlessClass {
export function thunk(b : typeof blah) {

}

/**
* A problematic self referential function
* @param b troublemaker
*/
export function quik(b: typeof quik) {}
Loading