microsoft / microsoft/TypeScript
symbolToName does handle exports of namespaces
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.2.2
Search Terms: symbolToName, exports, declaration, .d.ts
TypeScript cannot emit the name for a symbol that's declared in an inner namespace but re-exported in the outer namespace. That is, emitting the type name of a symbol does not take an alias created by an export {x as y} statement into account.
This comes up when trying to use the chrome.debugger declaration file. Because debugger is a reserved keyword, the .d.ts is defined using a fake, unexported inner namespace called _debugger, and re-exports it using export {_debugger as debugger};. TypeScript then cannot produce .d.ts files when trying to generate the name for a symbol.
Code
// decl.d.ts
declare module chrome {
namespace _debugger {
export class Foo {}
}
export function getFoo(): debugger.Foo;
export {_debugger as debugger};
}
// user.ts
export const x = chrome.getFoo();
Run tsc --declaration.
Expected behavior:
// user.d.ts
export declare const x: chrome.debugger.Foo;
Actual behavior:
test.ts:1:14 - error TS4025: Exported variable 'x' has or is using private name '_debugger.Foo'.
1 export const x = chrome.getFoo();
~
Playground Link: n/a
Related Issues:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with decl.d.ts and user.ts by running tsc --declaration, then trace the compiler's symbolToName handling for the re-exported _debugger namespace. Compare the generated declaration with the expected chrome.debugger.Foo name and use the existing compiler tests around declaration emit if available to verify the fix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100