typedoc icon indicating copy to clipboard operation
typedoc copied to clipboard

TypeDoc crashes during link resolver

Open andyferris opened this issue 1 year ago • 6 comments

Search terms

LinkResolverPlugin, kindOf, unexpected error

Expected Behavior

My typedoc compiled fine on version 0.25.4, and I expected it to continue to work with 0.25.5.

Actual Behavior

When upgrading typedoc to 0.25.5, it now crashes with the following message:

TypeDoc exiting with unexpected error:
TypeError: Cannot read properties of undefined (reading 'kindOf')
    at /.../node_modules/typedoc/dist/lib/models/types.js:687:63
    at Array.find (<anonymous>)
    at get reflection [as reflection] (/.../node_modules/typedoc/dist/lib/models/types.js:687:43)
    at _classThis.resolveLinks (/.../node_modules/typedoc/dist/lib/converter/plugins/LinkResolverPlugin.js:102:27)
    at _classThis.onResolve (/.../node_modules/typedoc/dist/lib/converter/plugins/LinkResolverPlugin.js:85:18)
    at triggerEvents (/.../node_modules/typedoc/dist/lib/utils/events.js:191:43)
    at triggerApi (/.../node_modules/typedoc/dist/lib/utils/events.js:167:13)
    at eventsApi (/.../node_modules/typedoc/dist/lib/utils/events.js:60:18)
    at _classThis.trigger (/.../node_modules/typedoc/dist/lib/utils/events.js:389:13)
    at _classThis.resolve (/.../node_modules/typedoc/dist/lib/converter/converter.js:335:18)

The same is true for higher versions, like 0.25.7.

Steps to reproduce the bug

Upgrade from version <= 0.25.4 to version >= 0.25.5, and rerun.

In case it is useful, in version <= 0.25.4 we get warnings to the effect of X, defined in /.../example.ts, is referenced by Y but not included in the documentation. Perhaps these are causing an issue in the newer versions of TypeDoc?

I'm sorry I can't provide any more information. Our project is reasonably large (and private). I'm hoping you can identify the issue by figuring out what changed between 0.25.4 and 0.25.5.

Environment

  • Typedoc version: 0.25.5
  • TypeScript version: 5.3.3
  • Node.js version: 20.11.0
  • OS: Ubuntu 22.04

andyferris avatar Feb 06 '24 13:02 andyferris

This is probably caused by 63704904523ec025fc08713b4c1156208972783e, specifically https://github.com/TypeStrong/typedoc/commit/63704904523ec025fc08713b4c1156208972783e#diff-28b49c0a2528c726938d5b8ad6f68b2b12e25994b5cfb3d55b449447e2fcc09dR255

Going to be difficult to fix the underlying issue with this without a reproduction, as that assert ought to be safe in this context. Just fixing the symptom is easy, but not the right thing to do from my current understanding of that, which is admittedly a month and a bit old now... have been lots of other problems to take up brain space.

Gerrit0 avatar Feb 07 '24 02:02 Gerrit0

Are you running with any plugins? I looked at the reflection removal code again, and am not seeing anything obvious which would cause this issue..

Gerrit0 avatar Feb 07 '24 03:02 Gerrit0

I get the same error message, with this little code snippet:

const f = () => 1;

/** doc
 */
export type ReturnOfF = ReturnType<typeof f>;

and when I run typedoc --excludeNotDocumented --out docs ./src/test.ts. When I omit --excludeNotDocumented the error goes away.

ebekebe avatar Feb 14 '24 10:02 ebekebe

Are you running with any plugins?

We are using typedoc-plugin-markdown and typedoc-plugin-merge-modules. (But the symptom likely is related to what @ebekebe wrote above - we definitely use ReturnType and have undocumented items).

andyferris avatar Feb 14 '24 10:02 andyferris

I put that snippet into a project and can't seem to reproduce still:

All of these generate docs successfully:

npx [email protected] src/gh2496.ts
npx [email protected] src/gh2496.ts --excludeNotDocumented
npx typedoc@latest src/gh2496.ts --excludeNotDocumented

I also tried exporting/not exporting f and including a link to f in ReturnOfF's documentation comment... none of these resulted in a crash.

Gerrit0 avatar Feb 18 '24 04:02 Gerrit0

Apologies, I couldn't reproduce it with my above snippet either. I don't know where the mistake happened, but here is the slightly modified version that does fail:

export function f() {
    return 1
}

/** doc
 */
export type ReturnOfF = ReturnType<typeof f>;

and the command:

❯ npx [email protected] --excludeNotDocumented --out docs src/test.ts
TypeDoc exiting with unexpected error:
TypeError: Cannot read properties of undefined (reading 'kindOf')
...

ebekebe avatar Feb 19 '24 10:02 ebekebe

Thanks! That does it, very confused as to why I used to symbol in removeReflection now...

Gerrit0 avatar Feb 23 '24 18:02 Gerrit0