W3cubDocs

/Kotlin

JsModule

Platform and version requirements: JS (1.1)
@Target([AnnotationTarget.CLASS, AnnotationTarget.PROPERTY, AnnotationTarget.FUNCTION, AnnotationTarget.FILE]) annotation class JsModule

Denotes an external declaration that must be imported from native JavaScript library.

The compiler produces the code relevant for the target module system, for example, in case of CommonJS, it will import the declaration via the require(...) function.

The annotation can be used on top-level external declarations (classes, properties, functions) and files. In case of file (which can't be external) the following rule applies: all the declarations in the file must be external. By applying @JsModule(...) on a file you tell the compiler to import a JavaScript object that contain all the declarations from the file.

Example:

@JsModule("jquery")
external abstract class JQuery() {
    // some declarations here
}

@JsModule("jquery")
external fun JQuery(element: Element): JQuery

Constructors

Platform and version requirements: JS (1.1)

<init>

Denotes an external declaration that must be imported from native JavaScript library.

JsModule(import: String)

Properties

Platform and version requirements: JS (1.1)

import

name of a module to import declaration from. It is not interpreted by the Kotlin compiler, it's passed as is directly to the target module system.

val import: String

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.js/-js-module/index.html