-
Notifications
You must be signed in to change notification settings - Fork 17
Recommending export {}
maybe not so good?
#7
Comments
@ljharb That was my suggestion (originally in nodejs/node-eps#3 (comment)). It's not supposed to export an object (or anything). From what I've been able to tell, See also #3. |
aha, good call. You're right that |
Cool, thanks for confirming. Since it may not be clear to a lot of people what that syntax represents, maybe it'd make sense to include a quick note explaining it. On a side note, what kind of danger did you have in mind if an object had been exported? In general modules are often going to export mutable objects, right? E.g. |
If an object was exported, people might rely on being able to set and get properties on it, and even if that's common, it's still an uninintended API contract. |
Thanks. While it should never be advertised and people shouldn't rely on unadvertised stuff that just happens to be there, I see what you mean. That actually highlights what we all agree on -- that it's better to not export anything at all, as that could be similarly abused (just by importing it when it's never intended for external use and is therefore subject to change at any time). |
The text says "should specify an export {} to make their intentions clear and avoid accidental parse errors while removing import statements.". If you're simply saying "should specify any export" then I agree with that - but I'd think exporting a mutable object is a dangerous casual API to create, whereas
export default null
orexport default undefined
is safe.Could we change the text to recommend
export default undefined
?The text was updated successfully, but these errors were encountered: