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

Mixins cause: TypeError: Cannot read property 'forEach' of undefined #1207

Closed
1 task done
zslayton opened this issue Feb 14, 2020 · 2 comments · Fixed by #1208
Closed
1 task done

Mixins cause: TypeError: Cannot read property 'forEach' of undefined #1207

zslayton opened this issue Feb 14, 2020 · 2 comments · Fixed by #1208
Labels
bug Functionality does not match expectation

Comments

@zslayton
Copy link
Contributor

zslayton commented Feb 14, 2020

I have a Typescript codebase that employs mixins.

Running typedoc fails with the following stack trace:

Using TypeScript 3.7.5 from node_modules/typescript/lib
node_modules/typedoc/dist/lib/converter/nodes/class.js:65
                            && typeToInheritFrom.symbol.declarations.forEach((declaration) => {
                                                                     ^

TypeError: Cannot read property 'forEach' of undefined
    at typesToInheritFrom.forEach (node_modules/typedoc/dist/lib/converter/nodes/class.js:65:70)
    at Array.forEach (<anonymous>)
    at context.withScope (node_modules/typedoc/dist/lib/converter/nodes/class.js:62:40)
    at Context.withScope (node_modules/typedoc/dist/lib/converter/context.js:101:9)
    at ClassConverter.convert (node_modules/typedoc/dist/lib/converter/nodes/class.js:33:17)
    at Converter.convertNode (node_modules/typedoc/dist/lib/converter/converter.js:116:53)
    at Context.inherit (node_modules/typedoc/dist/lib/converter/context.js:140:24)
    at typeToInheritFrom.symbol.typeToInheritFrom.symbol.declarations.forEach (node_modules/typedoc/dist/lib/converter/nodes/class.js:66:37)
    at Array.forEach (<anonymous>)
    at typesToInheritFrom.forEach (node_modules/typedoc/dist/lib/converter/nodes/class.js:65:70)

The issue is caused by this code, reproduced here with slightly different formatting:

typesToInheritFrom.forEach((typeToInheritFrom) => {
    typeToInheritFrom.symbol
    && typeToInheritFrom.symbol.declarations.forEach((declaration) => {
       context.inherit(declaration, baseType.typeArguments);
    });
});

If I change it to:

typesToInheritFrom.forEach((typeToInheritFrom) => {
    typeToInheritFrom.symbol
    && typeToInheritFrom.symbol.declarations // <--- Make sure this is defined
    && typeToInheritFrom.symbol.declarations.forEach((declaration) => {
       context.inherit(declaration, baseType.typeArguments);
    });
});

then documentation is generated normally. I have not studied the code long enough to understand its intent, so I'm unsure if this change is the best approach.

This failure did not occur in my project until I started using mixins. Additionally, the code above was added in a PR to introduce mixin support.

Expected Behavior

Typedoc should finish generating documentation successfully.

Actual Behavior

Typedoc throws an Error, preventing documentation from being generated and causing CI builds to fail.

Steps to reproduce the bug

typedoc: {
  build: {
    src: 'src/**/*'
  }
}

Environment

Laptop

  • Typedoc version: 0.16.9
  • Node.js version: 11.13.0
  • OS: mac OS mojave

Here's a link to the failing Travis CI Build, which runs on Node v8, v10, and v12 on Linux.

@zslayton zslayton added the bug Functionality does not match expectation label Feb 14, 2020
zslayton pushed a commit to amazon-ion/ion-js that referenced this issue Feb 14, 2020
Due to an issue[1] in typedoc's mixin support,
the documentation generation phase of the
release process fails.

This commit points the typedoc dependency to a
custom fork[2] that contains a fix. We can and
should back this change out later when
mainline is fixed.

[1] TypeStrong/typedoc#1207
[2] https://github.com/zslayton/typedoc/
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Feb 15, 2020

This is really weird, my first instinct was that typeToInheritFrom.symbol was an internal definition that we used and thus couldn't rely on TS's declaration file for accurate types, but this doesn't seem to be the case.

I really don't want to add checks for undefined when the TS declaration file claims it will never be undefined, but maybe the TS types are just wrong here? Looking more deeply into it.

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Feb 15, 2020

I'm beginning to think this is a TS bug... I've tried to reduce it to a smaller example but haven't been able to. For now I'll just merge the PR with a note that this is really weird and needs further investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Functionality does not match expectation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants