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

[api-extractor] Error caused by using the same name for an interface and namespace #1108

Open
akshay-madhukar opened this issue Feb 22, 2019 · 6 comments
Labels
ae-ambiguous-ids This issue belongs to a set of bugs tracked by Pete bug Something isn't working as intended repro confirmed The issue comments included repro instructions, and the maintainers reproduced the problem

Comments

@akshay-madhukar
Copy link

When an interface and a namespace have the same name as shown by TestName in this sample .d.ts file

interface TestName {
    type: number;
    index: number;
    size: number;
}

export declare namespace TestName {
    function createDefault(): TestName;
}

export { default as Log } from './log/Log';

the following error is seen in v7.0.18

Error: Internal Error: _notifyReferencedAstEntity() called after analysis is already complete
You have encountered a software defect. Please consider reporting the issue to the maintainers of this application.

However, if the last export is omitted, and only the interface and namespace are included, the api-extractor runs with no issues. There must be at least one additional export for the error to appear.

@octogonz octogonz added the bug Something isn't working as intended label Feb 22, 2019
@octogonz
Copy link
Collaborator

Which release of API Extractor are you using?

@akshay-madhukar
Copy link
Author

I am using 7.0.18

@octogonz
Copy link
Collaborator

I confirmed that this is a bug. Thanks for providing the repro.

@octogonz octogonz added the repro confirmed The issue comments included repro instructions, and the maintainers reproduced the problem label Mar 13, 2019
@octogonz
Copy link
Collaborator

octogonz commented Mar 13, 2019

@akshay-madhukar The inconsistency arises because namespace TestName is exported but interface TestName is not. I actually didn't know this was even allowed in TypeScript. In most cases you would get this error:

(TS2395) Individual declarations in merged declaration '__' must be all exported or all local.

I guess interfaces are special because they don't correspond to an actual JavaScript object, so the export is only conceptual.

This is an API Extractor bug, and we should fix it. But in the meantime as a workaround you can export the interface.

If the interface is supposed to be private, very soon I'm going to implement #972 which will allow you to mark it as @internal while marking the namespace as @public.

@mhofman
Copy link

mhofman commented May 29, 2019

It seems that api-extractor doesn't have any error anymore with an interface and namespace merged declaration, but api-documenter doesn't seem to generate the documentation properly.

export declare namespace Test {
    export type Kind = string;

    /**
     * Create a {@link (Test:interface)} of the given kind
     *
     * @param kind - The {@link (Test:namespace).Kind | kind} of the test.
     */
    export function create(kind: Kind): Test;
}

/**
 * A Test
 *
 * @public
 */
export interface Test {
    kind: Test.Kind;
}

Will not generate any documentation for the interface.

The following warnings are also produced:

WARNING: Unable to resolve reference "(Test:interface)": The member reference "Test" was ambiguous
WARNING: Unable to resolve reference "(Test:namespace).Kind": The member reference "Test" was ambiguous
WARNING: Unable to resolve reference "(Test:interface)": The member reference "Test" was ambiguous

@octogonz octogonz added the ae-ambiguous-ids This issue belongs to a set of bugs tracked by Pete label Jun 2, 2019
@octogonz
Copy link
Collaborator

octogonz commented Jun 2, 2019

This issue belongs to a family of closely related issues. I've created metaissue #1308 to come up with a unified fix that tackles them all together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ae-ambiguous-ids This issue belongs to a set of bugs tracked by Pete bug Something isn't working as intended repro confirmed The issue comments included repro instructions, and the maintainers reproduced the problem
Projects
Status: AE/AD
Development

No branches or pull requests

3 participants