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] dts rollup cannot handle "import Foo = Bar.Baz" syntax as external import correctly #2005

Open
1 of 2 tasks
adventure-yunfei opened this issue Jul 7, 2020 · 2 comments

Comments

@adventure-yunfei
Copy link
Contributor

adventure-yunfei commented Jul 7, 2020

Please prefix the issue title with the project name i.e. [rush], [api-extractor] etc.

Is this a feature or a bug?

  • Feature
  • Bug

Please describe the actual behavior.

If we use "import Foo = Bar.Baz" syntax for external package, dts rollup will treat those symbols as local symbols, and produce incorrect dts result.

If the issue is a bug, how can we reproduce it? Please provide detailed steps and include a GitHub branch if applicable. Your issue will get resolved faster if you can make it easy to investigate.

With following "foo" package definition:

// node_modules/foo/index.d.ts
export declare class Class_inside_foo {
	mem: number;
}

And following dts file:

// src/index.d.ts
import * as foo from 'foo';
import Class_inside_foo = foo.Class_inside_foo;
export declare class NormalClass {
    mem: Class_inside_foo;
}

Dts rollup by api-extractor will generator following dts result:

// dts.rollup.d.ts
declare class Class_inside_foo {
	mem: number;
}

export declare class NormalClass {
    mem: Class_inside_foo;
}

export { }

The "Class_inside_foo " declaration should be an external import, but instead it's treated as local declaration here.

What is the expected behavior?

May produce something like:

// dts.rollup.d.ts
import * as foo from 'foo';

export declare class NormalClass {
    mem: foo.Class_inside_foo;
}

export {}

If this is a bug, please provide the tool version, Node.js version, and OS.

  • Tool: api-extractor
  • Tool Version: 7.9.1
  • Node Version: v10.21.0
    • Is this a LTS version? yes
    • Have you tested on a LTS version?
  • OS: window 10
@adventure-yunfei adventure-yunfei changed the title [api-extractor] [api-extractor] dts rollup cannot handle "import Foo = Bar.Baz" syntax as external import correctly Jul 7, 2020
@adventure-yunfei
Copy link
Contributor Author

This syntax may be weird, but it's very useful if an external package has exports with multiple hierarchies.

BTW I've been little confused recently about different import/export syntax.
There're some discussions like microsoft/TypeScript#7185 (comment), and official Modules document. But I didn't find the description for import Foo = Bar.Baz; syntax. The most similar case is import Foo = require('bar'), and they both have the same syntax kind "ImportEqualsDeclaration".

@adventure-yunfei
Copy link
Contributor Author

A working prototype: adventure-yunfei#4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: AE/AD
Development

No branches or pull requests

1 participant