Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Improve "Function Types" support #6

Open
fvoronin opened this issue Mar 28, 2018 · 1 comment
Open

Improve "Function Types" support #6

fvoronin opened this issue Mar 28, 2018 · 1 comment

Comments

@fvoronin
Copy link

type2docfx (v0.9.79) has a problem with function types described with an interface.
For example, we have a module:

export interface ObservableGetter<T> {
    (): T;
}
export interface ObservableSetter<T> {
    (v: T): void;
}

export interface ObservableProperty<T> extends ObservableSetter<T>, ObservableGetter<T> {
}

export default class Observable {
    static accessor<T>(name: string): ObservableProperty<T>;
    static accessor(name: string) {
        return function(v?) {
            if (arguments.length) {
                // call internal set method
            } else {
                // call internal get method
            }
        }
    }
}

Run typedoc (v0.11.1) on it with json output and get result api.json.

If we pass that api.json to type2docfx, we get an error:

> type2docfx api.json .\
Class: test.Observable
 - Method: test.Observable.accessor
Interface: test.ObservableGetter
Interface: test.ObservableProperty
...\type2docfx\dist\jsonTraverse.js:220
    method.syntax.parameters = fillParameters(node.signatures[signatureIndex].parameters);
                             ^

TypeError: Cannot set property 'parameters' of undefined
    at extractInformationFromSignature (...\type2docfx\dist\jsonTraverse.js:220:30)
    at traverse (...\type2docfx\dist\jsonTraverse.js:199:17)
    at ...\type2docfx\dist\jsonTraverse.js:210:17
    at Array.forEach (<anonymous>)
    at Object.traverse (...\type2docfx\dist\jsonTraverse.js:205:23)
    at Object.<anonymous> (...\type2docfx\dist\main.js:78:20)
    at Module._compile (module.js:649:30)
    at Object.Module._extensions..js (module.js:660:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
@stratospheres
Copy link

Having the same problem. Not entirely sure why, but the "syntax" property isn't initialized in this case. Just adding an initializer in the jsonTraverse.ts file in the extractInformationFromSignature seems to fix (but might not be the best way)...

// init syntax object if it's not already there...
method.syntax = method.syntax || {};

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants