Quick Summary: I'd defined a port in Elm without actually using it in Elm. Next thing I see an error from JS: app.ports.myPort is undefined. I spend time trying to figure out why a defined port isn't on app.ports. A message from the compiler explaining it has been dead-code eliminated would save that time!
port module Main
port myPort : a -> Cmd msg
-- no actual use of myPort in my Elm code (I'd commented it out)
var app = Elm.Main.init({
node: document.getElementById('elm')
});
app.ports.myPort // undefined
Sounds like a convenience, but does it justify weighing down the compiled JS?
(Probably ok for debug builds, but for optimized builds? And then, is the difference in behaviour too surprising?)
Also, do tools like dillonkearns/elm-typescript-interop allow warning about "eliminated" ports via static analysis in TypeScript?
No need for the message to be in the compiled JS, just from the compiler to the user during compilation.
A message from the compiled JS in debug builds would be even better because the developer is even more likely to see it.
Calling a send method on such port in debug build could show a warning that the port is not subscribed and nothing will be delivered anywhere.
Most helpful comment
No need for the message to be in the compiled JS, just from the compiler to the user during compilation.