Volodymyr Galandzij
06/10/2025, 5:19 PMPromise<List<Item>>
is exported to TypeScript as Promise<any>
while Promise<JsArray<Item>>
preserves both the container and item types?
Is it expected behavior and we should use `JsArray`/`JsReadonlyArray` to preserve list item type in the Typescript declarations?
// JsItemsRepository.kt file
@OptIn(ExperimentalJsCollectionsApi::class)
class JsItemsRepository() {
fun getAllArrayAsync(): Promise<JsReadonlyArray<Item>> = scope.promise { … }
fun getAllListAsync(): Promise<List<Item>> = scope.promise { … }
fun getFirstAsync(): Promise<Item> = scope.promise { … }
}
// mymodule.d.ts file
class JsItemsRepository {
getAllArrayAsync(): Promise<ReadonlyArray<com.test.my.Item>>;
getAllListAsync(): Promise<any/* kotlin.collections.KtList<com.test.my.Item> */>;
getFirstAsync(): Promise<com.test.my.Item>;
}
Edoardo Luppi
06/10/2025, 5:43 PMVolodymyr Galandzij
06/10/2025, 5:44 PMVolodymyr Galandzij
06/10/2025, 5:51 PMjs
block is:
kotlin {
js {
browser { }
binaries.executable()
generateTypeScriptDefinitions()
}
}
Edoardo Luppi
06/10/2025, 5:54 PMList
must be exported.
To prove it, add an exported dummy function that returns List<Item>
, and you'll see the Promise
type will be correctly generated.
@Artem Kobzar let me know if you know of an open issue for this one, or if I have to create one.Volodymyr Galandzij
06/10/2025, 5:57 PMclass JsItemRepository {
getItems(): kotlin.collections.KtList<com.test.my.Item>;
getAllAsync(): Promise<ReadonlyArray<com.test.my.Item>>;
getAllListAsync(): Promise<kotlin.collections.KtList<com.test.my.Item>>;
getFirstAsync(): Promise<com.test.my.Item>;
}
Volodymyr Galandzij
06/10/2025, 5:58 PMEdoardo Luppi
06/10/2025, 5:58 PMArtem Kobzar
06/11/2025, 9:08 AMVolodymyr Galandzij
06/11/2025, 9:10 AMArtem Kobzar
06/11/2025, 9:14 AMPromise<List<Int>>
return and the text of the generated d.ts for the function.
So, it would be like this:
fun foo(): Promise<List<Int>> = ...
The generated d.ts:
declare function foo(): Promise<any/* kotlin.collections.KtList<number> */>>
However the expected behavior is:
declare function foo(): Promise<kotlin.collections.KtList<number>>>
Edoardo Luppi
06/11/2025, 9:17 AM// main.kt
// List won't be exported to KtList
@JsExport
fun promiseListExport(): Promise<List<Int>> {
return Promise.resolve(listOf(1))
}
// Uncomment the following function so that the compiler
// picks up the List type and correctly exports it
// @JsExport
// fun listExport(): List<Int> {
// return listOf(1)
// }
Volodymyr Galandzij
06/13/2025, 8:50 AM