Fix redundant export {} in declaration file#58912
Fix redundant export {} in declaration file#58912Dunqing wants to merge 3 commits intomicrosoft:mainfrom
export {} in declaration file#58912Conversation
@microsoft-github-policy-service agree |
export {} in declaration file
weswigham
left a comment
There was a problem hiding this comment.
This is not sufficient to fix the issue. I'm not sure @RyanCavanaugh remembered in the linked issue, but we emit a export {} not just to ensure module-ness, but to actually make privately scoped names work at all - unless a declaration file has a export declaration (not an export modifier - an export declaration) all names are implicitly exported. If we stop emitting this marker, that behavior has to change, so privates remain private. Breaking that will be a breaking change, though! Declaration files like
type A = 1;
export interface B {}allow importing A today, so forbidding that is a break - arguably a good one, but it'll be a break with a declaration file behavior we've had since approximately the origin of declaration files.
|
And here I always assumed declaration files worked exactly like source files w.r.t. what’s exported - before today I would have confidently told anyone who asked that |
|
Declaration files have really, really weird export semantics. Been trying to augment ts-eslint to handle that in typescript-eslint/typescript-eslint#8611 but it's definitely a battle, so not surprised to see this be wrong. |
|
It hasn't really needed to be something we've needed to think about since our declaration emitter started emitting privates and |
|
This is weird. I am implementing the So I want to ask, when a third-party tool wants to implement |
|
Yes. If you're implementing isolated declarations, you should be using |
|
For future implementors of isolated declarations, you need port this "bug" as a feature 😁 We are already using the |
|
Yeah; if you do find anything weird, please do report it so we can at least make sure it isn't actually a bug. e.g. oxc-project/oxc#3798 is Not quite sure where to document |
Fixes #51338