Skip to content
This repository has been archived by the owner on Nov 6, 2019. It is now read-only.

Generated extension functions don't compile #109

Closed
epabst opened this issue Oct 2, 2018 · 0 comments · Fixed by #121
Closed

Generated extension functions don't compile #109

epabst opened this issue Oct 2, 2018 · 0 comments · Fixed by #121

Comments

@epabst
Copy link
Contributor

epabst commented Oct 2, 2018

Example:

/// <reference path="../../testDefinitelyTyped/DefinitelyTyped/jquery/jquery.d.ts" />

interface JQuery {
    foo()
    bar
    [prop: string]: number;
    someField: string;
    optionalField?: any;
    (resourceId:string, hash?:any, callback?:Function): void;
}

results in:

external fun JQuery.foo(): Unit = definedExternally
external var JQuery.bar: Any get() = definedExternally; set(value) = definedExternally
@nativeGetter
external operator fun JQuery.get(prop: String): Number? = definedExternally
@nativeSetter
external operator fun JQuery.set(prop: String, value: Number): Unit = definedExternally
external var JQuery.someField: String get() = definedExternally; set(value) = definedExternally
external var JQuery.optionalField: Any? get() = definedExternally; set(value) = definedExternally
@nativeInvoke
external operator fun JQuery.invoke(resourceId: String, hash: Any? = definedExternally /* null */, callback: Function<*>? = definedExternally /* null */): Unit = definedExternally

which fails with compile error "Declaration of such kind (extension function) cant be external", etc.
It should be:

fun JQuery.foo(): Unit { this.asDynamic().foo() }
var JQuery.bar: Any get() = this.asDynamic().bar; set(value) { this.asDynamic().bar = value }
operator fun JQuery.get(prop: String): Number? { return this.asDynamic().get(prop) }
operator fun JQuery.set(prop: String, value: Number): Unit { this.asDynamic().set(prop, value) }
var JQuery.someField: String get() = this.asDynamic().someField; set(value) { this.asDynamic().someField = value }
var JQuery.optionalField: Any? get() = this.asDynamic().optionalField; set(value) { this.asDynamic().optionalField = value }
operator fun JQuery.invoke(resourceId: String, hash: Any? = null, callback: Function<*>? = null): Unit { this.asDynamic().invoke(resourceId, hash, callback) }
epabst added a commit to epabst/ts2kt that referenced this issue Nov 14, 2018
Schahen pushed a commit that referenced this issue Nov 29, 2018
* Don't specify external for extension functions and variables

This fixes #109

* Remove @file:JsQualifier if all functions & variables are extensions

This fixes a compilation error that external functions and variables
can't be in a file annotated with @file:JsQualifier.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant