Running the following Scala code compiled into scala-js version 0.8.0, I get the following error:
An undefined behavior was detected: undefined is not an instance of java.lang.String
trait MyDataType extends js.Any {
var wordy: String = js.native
}
// This usually comes from the backend.
val dataStruct = js.Dynamic.literal().asInstanceOf[MyDataType]
val isWordy = dataStruct.wordy
Scala-js fiddle (press CTRL+ENTER)
After investigation, the code above is compiled as:
var dataStruct = {};
var isWordy = $as_T(dataStruct["wordy"]); // Line causing problem.
Obviously it is because of this $as_T
which causes this trouble.
How can I make sure that the code above is unchecked ?
Edit I found a workaround which is not very elegant.
val isWordy = dataStruct.asInstanceOf[js.Dynamic].wordy
But still, why this $as_T
?