EDIT: This is not supported yet and tracked on Kotlin YouTrack
I'm trying to write a Kotlin external
declaration matching the following Typescript interface (this is valid TS to represent JavaScript accesses via headers['content-length']
):
export interface Headers {
'content-length'?: string;
}
Dukat generates the following, which should be considered valid:
external interface Headers {
var `content-length`: String? get() = definedExternally; set(value) = definedExternally
}
But now the compiler complains with:
Name contains illegal chars that can't appear in JavaScript identifier
It is true that it can't appear in a JS identifier, but it doesn't have to. All Kotlin accesses to this property like:
val length = headers.`content-length`
could be valid if compiled to const length = headers["content-length"]
.
I tried to use @JsName
to work around it the following ways:
@JsName("content-length")
@JsName("'content-length'")
@JsName("\"content-length\"")
But all of these fail because they only allow strings that are valid JS identifiers. Is there a way to work around this?