Why isn't this a valid js syntax? Any way around ...
# react
n
Why isn't this a valid js syntax? Any way around it without having to manually type it out
Copy code
fun getDefaultValuesFromProfile(profile: ProfileModel): dynamic {
    val d : dynamic = js("{ defaultValues : {...profile}}")
    return d
}
Which should be totally valid in ts (javascript)
Copy code
function test(profile: IProfile) {
  const test = { defaultValues: { ...profile } };
}
c
What is the error message?
n
Invalid js syntax @CLOVIS , in the IDE
c
Is that an IDEA warning, a compilation error, or a runtime error?
n
@CLOVIS IDE error and when compiling I get
Copy code
> Task :web-app:compileDevelopmentExecutableKotlinJs FAILED
e: org.jetbrains.kotlin.com.google.gwt.dev.js.parserExceptions.JsParserException: syntax error at (0, 19)
With
Copy code
fun getDefaultValuesFromProfile(profile: ProfileModel): dynamic {
    val d: dynamic = js("{ defaultValues : {...profile}}")
t
Common recomendations: 1. Avoid
dynamic
2. Avoid
js
calls First step:
Copy code
fun getDefaultValuesFromProfile(profile: ProfileModel): dynamic {
    return jso {
        defaultValues = Object.clone(profile)
    }
}
Second step: Strict contracts, using external interfaces
n
@turansky thanks, yeah I'll have to focus a bit more on my library wrappers. I'll probably post a separate question related to that as I've had some issues getting it to work with interfaces and types. This is kinda hacky to get it to work for now
t
I know one “legal”
js
call -
js("({})")
In most cases you can describe types without
dynamic
usages Typical solutions you can find in: 1. Wrappers 2. Modern examples. Latest practices you can find here