Kotlin / dukat

Converter of <any kind of declarations> to Kotlin external declarations
552 stars 42 forks source link

Unroll correctly setters for union types #311

Closed Schahen closed 4 years ago

Schahen commented 4 years ago

Following code:

interface Dict<T> {
    [key: string]: T | undefined;
}

interface BasicHeaders extends Dict<string | string[]> { }

it converted to:

external interface Dict<T> {
    @nativeGetter
    operator fun get(key: String): T?
    @nativeSetter
    operator fun set(key: String, value: T?)
}

external interface BasicHeaders : Dict<dynamic /* String | Array<String> */> {
    override operator fun get(key: String): Any?
    override operator fun set(key: String, value: Any?)
}

while actually what we really do expect to have is a set unrolled to:

external interface BasicHeaders : Dict<dynamic /* String | Array<String> */> {
    override operator fun get(key: String): Any?
    override operator fun set(key: String, value: String?)
    override operator fun set(key: String, value: Array<String>?)
}
Schahen commented 4 years ago

In fact we don't even need to inherit Dict, so the minimal example would be:

interface BasicHeaders {
    'retry-after'?: string;
    'set-cookie'?: string[];
}
Schahen commented 4 years ago

this one is closely related to https://github.com/Kotlin/dukat/issues/310