haxetink / tink_web

Tinkerbell Web Framework
https://haxetink.github.io/tink_web
43 stars 14 forks source link

Parametrized interface #79

Closed kevinresol closed 4 years ago

kevinresol commented 5 years ago
interface BaseApi<T> {
  @:get('/')
  function get():Promise<T>;
}

tink_json cannot parse BaseApi.T. For parsing custom data, please see https://github.com/haxetink/tink_json#custom-abstracts

I think this should work because the actual usage must contain a concrete type for T?

back2dos commented 5 years ago

Hmm, random guess, but if you route over typedef FooApi = BaseApi<Foo> does it work? ^^

kevinresol commented 5 years ago

but if you route over typedef FooApi = BaseApi<Foo> does it work? ^^

Surprisingly, yes! (case 1 below)

But in fact I am trying to extend interfaces... (case 2)

package;

using tink.CoreApi;

class Main {
    static function main() {
        var remote = new tink.web.proxy.Remote<TypedefApi>(null, null); // works
        var remote = new tink.web.proxy.Remote<ExtendApi>(null, null); // fails
        var remote = new tink.web.proxy.Remote<ExtendTypedefApi>(null, null); // fails
    }
}

interface BaseApi<T> {
  @:get('/')
  function get():Promise<T>;
}

typedef TypedefApi = BaseApi<{foo:String}>;
interface ExtendApi extends BaseApi<{foo:String}> {}
interface ExtendTypedefApi extends TypedefApi {}