Using JS/TS I can simply `import` or `require` (in...
# javascript
e
Using JS/TS I can simply
import
or
require
(inside a function) a JSON file. How does this translate to KotlinJS?
t
Untitled
e
@turansky thanks! I suppose "typing" the JSON file isn't as straightforward as declaring an
interface
in TS
t
In TS - multiple interfaces In Kotlin - multiple
require
Copy code
@JsName("require")
external fun requireJson(path: String): String

@JsName("require")
external fun requireCss(path: String): Array<dynamic>
e
@turansky thanks. It seems I could also use the
unsafeCast
option to convert the file content to a typed structure.
t
Copy code
external fun <T:Any> require(path: String): T
✔️ 1
God method
😂 1
e
@turansky when I require something like
Copy code
interface Dictionary {
  val words: Array<String>
}

require<Dictionary>("./dictionary.json")
the generated JS code is
Copy code
var dictionary = require('./dictionary.json');
var tmp0_forEach_0 = dictionary._get_words___error();
Can't understand why honestly
t
It depends on webpack loader which you use
AFAIK
require
return
String
for json by default
e
But even given that, in JS I can access JSON members simply via
dictionary.words
While here a strange function call is generated instead
When I use a class, this is outputted
Copy code
var tmp0_forEach_0 = dictionary.words__error;
Almost...
@turansky I switched to the legacy compiler and now it seems to work
Copy code
var dictionary = require('./dictionary.json');
var $receiver = dictionary.words;
😀 1
t
1. Update
Atomicfu
doc 2. Report
require
error in IR 🙂
e
t
What about
1.4.30-M1
?
e
@turansky let me try
t
Possibly bug is already fixed
e
@turansky no it's the same 😞
Luckily this is a small product that will be only internal
t
IR in alpha - bugs are expected
e
@turansky just curious, have you ever used KotlinJS in production?
t
Yes, I have :)
Legacy have known problems, which I fix via plugins
IR isn’t ready for production in my cases
e
@turansky thanks, that's reassuring 😄
t
You can vote here for future comfortable Kotlin/JS: 1. KT-37710 2. KT-42871 3. KT-43434
e
@turansky I've quickly read them all, all seems reasonable points, thanks
t
FYI - about external libraries
e
@turansky in case of non-ES6 modules, isn't the DCE able to strip away dependencies code that isn't used? If it cannot it means another external optimization step is required
t
DCE - to remove Kotlin dead code ES6 - to remove JS dead code (by Webpack)
e
Oh, so the DCE is stricly related to Kotlin, now I understand better
t
If you don’t use JS libraries - DCE is enough
e
@turansky I was looking at Scala.js and damn since 1.0 they improved a lot. I'd say Kotlin needs to catch up
t
They have modern export model But looks like mixin problem is open for Scala.js too
e
@turansky I've tried Scala again. They have better JS support, but the Kotlin MP projects are still the best choice.
MP builds using SBT are pretty painful
t
No “silver bullet” detected 🙂
e
@turansky yep, definitely. We happen to develop in years of transitions
t
…. N+1. GWT and elemental2 N+2. Kotlin/JS • you are here N+3. Kotlin/JS + (ES6, Mixins, function entry points)
Kotlin/JS already have some problems. GWT, Scala.js and TypeScript have checked solutions for Kotlin/JS, which will create it more useful For now main point for me - IR and future ES6 support
Scala.js have not OOB mixins support Kotlin/JS have it inside, checks can be added by plugin