Repository navigation
Open
Labels
bugSomething isn't working as intendedSomething isn't working as intendedeffort: easyProbably a quick fix. Want to contribute? :-)Probably a quick fix. Want to contribute? :-)help wantedIf you're looking to contribute, this issue is a good place to start!If you're looking to contribute, this issue is a good place to start!repro confirmedThe issue comments included repro instructions, and the maintainers reproduced the problemThe issue comments included repro instructions, and the maintainers reproduced the problem
Description
Summary
If using declare var, the name will be lost in the fianl rollup file.
// const.d.ts
declare const _default: { a: string }
export default _default;
// var.d.ts
declare var _default: { a: string }
export default _default;
// index.d.ts
import Const from './const'
import Var from './var';
export { Const, Var }// rollup.d.ts
export declare const Const: { a: string };
export declare var _default: { a: string };
export { }Repro steps
- Clone https://github.com/qmhc/api-extractor-issue.git
- Install then run
pnpm run build:dts - Check
index.d.tsandrollup.d.tsin 'dist'
Expected result: export declare var Var: { a: string }
Actual result: export declare var _default: { a: string }
When more than one file includes declare var _default, the final rollup file will have errors.
// index.d.ts
import Var from './var';
import Var1 from './var1';
export { Var, Var1 }
// rollup.d.ts
export declare var _default: { a: string }; // get errors
export declare var _default: { b: string }; // get errors
export { }Details
I'm not sure if this is a known limitation or a bug.
Standard questions
Please answer these questions to help us investigate your issue more quickly:
| Question | Answer |
|---|---|
@microsoft/api-extractor version? |
Latest |
| Operating system? | Windows |
| API Extractor scenario? | rollups |
| Would you consider contributing a PR? | No |
| TypeScript compiler version? | 4.5.5 |
Node.js version (node -v)? |
16.13.1 |
Reacted by Sachin Joseph
Metadata
Metadata
Assignees
Labels
bugSomething isn't working as intendedSomething isn't working as intendedeffort: easyProbably a quick fix. Want to contribute? :-)Probably a quick fix. Want to contribute? :-)help wantedIf you're looking to contribute, this issue is a good place to start!If you're looking to contribute, this issue is a good place to start!repro confirmedThe issue comments included repro instructions, and the maintainers reproduced the problemThe issue comments included repro instructions, and the maintainers reproduced the problem
Type
Projects
- StatusShow more project fieldsAE/AD
Activity
octogonz commentedon Apr 14, 2022
This is a bug. We should fix it.
That said,
export defaultis not a recommended practice:import Button from './Checkbox';then the compiler cannot detect this mistake. Your code may even compile successfully if theButtonandCheckboxAPIs are similar enough, which is very confusing.import Manager from './RequestManager';) which means that if someone does a Find-in-Files or bulk Search+Replace forRequestManager, they can no longer have high confidence that it will find them allimport { Button } from './Button';. As far as I can tell, there really is no reason to useexport default, except for things that are truly anonymous such as importing a JSON resource.Thus, I'm really curious why your project wouldn't simply use
import { Var1 } from './var1';octogonz commentedon Apr 15, 2022
Rocco (@qmhc) thanks for the great repro. 👍 I debugged it, and the problem is here:
rushstack/apps/api-extractor/src/analyzer/ExportAnalyzer.ts
Lines 355 to 368 in c7e016b
The
SymbolFlags.FunctionScopedVariabletest is supposed to catch for examplexin this declaration:....but instead it is incorrectly detecting
Varin your repro:This seems like it might be a compiler bug -- I'm not sure I would consider
Varto be a "function-scoped variable."If I comment out the line
return undefined;then your .d.ts rollup gets generated correctly. However, probably thexcase would be broken.I'm on vacation so I can't investigate this further right now. But if we can figure out a good test to distinguish these two cases, it should be pretty easy for someone to make a PR.
Ron Buckton (@rbuckton) do you have any suggestions?
qmhc commentedon Apr 15, 2022
Pete Gonzalez (@octogonz) I quite agree with you for:
Once I wrote a vue component with jsx (for some tests), after the declaration file emitted I found it by accident.
Normally we should use tsx for type support instead of jsx (and when using tsx, this case will not appear).
I hesitated whether to report, because this may not a correct usage.
octogonz commentedon Apr 15, 2022
Even so, we should still try to fix this bug. 🙂