我刚刚设法在角度6打字稿文件中导入Kotlin编译的javascript模块。这并不容易,结果使我感到困惑。我想知道是否存在更优雅的方式。
最初,我使用Kotlin文件:
package com.example.test
data class SomeInterface(
var id: String? = null,
var value: String? = null
) {
}
Run Code Online (Sandbox Code Playgroud)
可以很好地编译为以下JavaScript
(function (root, factory) {
if (typeof define === 'function' && define.amd)
define(['exports', 'kotlin'], factory);
else if (typeof exports === 'object')
factory(module.exports, require('kotlin'));
else {
if (typeof kotlin === 'undefined') {
throw new Error("Error loading module 'TestKotlinCompiled'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to 'TestKotlinCompiled'.");
}
root.TestKotlinCompiled = factory(typeof TestKotlinCompiled === 'undefined' ? …Run Code Online (Sandbox Code Playgroud)