mozilla / sphinx-js

Autodoc-style extraction into Sphinx for your JS project
https://pypi.python.org/pypi/sphinx-js/
MIT License
282 stars 81 forks source link

Typescript: KeyError for optional Generic Fields #122

Open maximilianmaihoefner opened 5 years ago

maximilianmaihoefner commented 5 years ago

When trying to run sphinx-js over an interface with an optional field with a generic type a KeyError gets thrown.

The code being documented: interface GenericInterface<T> { optionalField?: T; }

Gives the following Error: Exception occurred: File "/usr/local/lib/python3.7/site-packages/sphinx_js/typedoc.py", line 123, in make_type_name node = self.nodelist[type.get('id')] KeyError: 201

Using: TypeScript 3.5.3 TypeDoc 0.15.0 Sphinx 2.2.0 Sphinx-JS 2.8

The workaround for now is to make the Field not optional, which is fine, but it would be better to have it supported by sphinx-js.

maximilianmaihoefner commented 5 years ago

Another workaround I found is to explicitly type the field as undefined e.g. optionalField: T | undefined. Which works for me. It still would be nice if this was supported or at least throw a more descriptive error, it was quite the hunt to find out what actually caused the error.

erikrose commented 5 years ago

Thanks for the report and the nicely reduced testcase! I can't promise when we'll get to this, but I'm personally interested in getting #120 landed, after which it should be much easier to navigate within our typescript module.