4 ms·
How does Scala.js deal with inconsistent browser APIs and type safety? Does it just include all of core-js and hope for the best?
by mbell 9y ago
How does Scala.js deal with inconsistent browser APIs and type safety? Does it just include all of core-js and hope for the best?
- raquo 9y agoI don't know, but I would be surprised if Scala.js does anything in that regard. It's a Scala-to-JS compiler, its job is to translate Scala code to JS code. Scala.js lets you require any npm modules, so you can `require()` any JS polyfills you want just like you would do if writing JS code by yourself.
- fwefwwfe 9y agoIt lets you define types for more safely interacting with other Javascript code. It doesn't magically make browsers have consistent behavior.
- mbell 9y agoWhat I'm getting at is how it handles type safety at the browser API boundary. e.g. how does it handle a situation like: `eventTgt.addEventListener('whatever', fn, true)` vs `eventTgt.addEventListener('whatever', fn, { passive: true })` Does it just allow 'Any' for the type of the third param and thus somewhat punt on type safety at the browser API boundary or is there some attempt at defining an algebraic type for that param? Or as another example, how would it handle the object passed to `fn` above, presumably some sort of event type, having different properties in different browsers?
- sjrd 9y agoIn the standard types for the DOM [1], only types for standardized browser APIs are made available. Browser inconsistencies wrt. standards are dealt with polyfills, either written in JS because they already exist, or you can write them in Scala.js too if you prefer. But Scala.js doesn't force the standard typings on you. If you prefer another strategy, you can write your own types for the browser. You could use overloads in your example above. That wouldn't prevent you from using the wrong overload on the wrong browser at the type system level, though, obviously. Doing so might be possible if you're willing to go very far with Scala's path-dependent types, but I won't go into details here. Scala.js users tend to prefer the earlier solutions. [1] https://github.com/scala-js/scala-js-dom https://github.com/scala-js/scala-js-dom
- fwefwwfe 9y ago> It lets you define types for more safely interacting with other Javascript code You define types for everything.
- audi100quattro 9y agoAbout as well as jquery-ui or bootstrap would deal with browser inconsistencies if that's what you use for pre-made widgets/forms/layouts/themes/etc.. as other have said, you can use any js library.