Elm ports automatic public export and internal visibility boundary
0 reputation · 17 Oct 2020, 18:07 UTC
Elm ports provide typed channels for JavaScript interop. The compiler validates port types at compile time, but does not enforce a visibility boundary for which ports are exposed to JavaScript.
All ports defined in a module are automatically exported from the module and become accessible to JavaScript consumers. There is no built-in mechanism to mark a port as internal or to restrict its JavaScript accessibility. The design was chosen to keep the module system simple and avoid complex visibility rules.
The goal is to define implementation-only ports without making them part of the public JavaScript API surface, while still using the documented port feature. The current constraint is that developers must manually ensure sensitive ports are not called from public JavaScript contexts.
Is there a documented way to restrict port visibility in Elm? Does the compiler provide any configuration or module boundary to treat ports as private? What permission boundary is recommended for modules that mix public and internal ports?