Marc
10/27/2026, 1:46 PMSharedFlow and StateFlow also planned? SharedFlow I could usually just cast to a flow, but for StateFlow having access to .value would be very useful.Artem Kobzar
10/27/2026, 1:52 PMFlow is supported. But it makes sense to support StateFlow as well.
CC: @Dmitry Khalanskiy [JB]Dmitry Khalanskiy [JB]
10/27/2026, 3:41 PMFlow object, in the upcoming release, you'll be able to use the for await syntax in JS with that object. Since StateFlow and SharedFlow are both inheriting from Flow, that means them as well. Accessing the .value of a StateFlow should be no different than accessing any val of any interface from JavaScript. Am I missing something?Marc
10/27/2026, 4:04 PM@JsExport works but my understanding was that if I update to the new release and I export a StateFlow -typed field from Kotlin, JS/TS code will then see it an exported Flow . If I now want to access .value, it will not be listed in the generated TS types and directly accessing it from JS will also not work because only the mangled getter will be generated (since StateFlow itself is not exported and only exporting it generates the JS-friendly direct accessors, as far as I know). I checked with a small repro of the same hierarchy (exported Flow, non-exported StateFlow) and the field is typed as Flow<...>/* StateFlow<...> */ in the .d.ts, and the impl class only gets get_value_<hash>_k$(), no get value().Artem Kobzar
10/27/2026, 4:11 PMvalue changed (what for await will do) but also to read it later. It could be done with something like this with just exported Flow , but I mean just accessing StateFlow with value instead of such code would be more DX-friendly:
const state = { value: null };
(async () => {
for await (const newValue of provideStateFlow()) {
state.value = newValue;
}
})();Marc
10/27/2026, 4:13 PMvalue is also available in non-async contexts, which is very useful for things like UI, where you need live updates but also a starting value (and you need it immediately).Dmitry Khalanskiy [JB]
10/27/2026, 5:08 PM.value, that much is clear.
Maybe I misunderstood howI for one certainly do misunderstand that as well, so please bear with me!works@JsExport
if I update to the new release and I export aWhy? If the field is-typed field from Kotlin, JS/TS code will then see it an exportedStateFlow.Flow
StateFlow, why would the compiler upcast it to Flow on its own?
sinceWhat I don't understand here is why it wouldn't be exported in the first place. If the compiler forgets some of the type information about the exported fields, this sounds like a bug worth filing.itself is not exportedStateFlow
Marc
10/28/2026, 10:10 AMWhy? If the field isMy understanding is that the compiler automatically falls back to the closest exported supertype, and only, why would the compiler upcast it toStateFlowon its own?Flow
Flow has been marked with @JsExport in the initial implementation from what I've seen, right? And in that case, the compiler will only expose fields/functions defined directly on that supertype. I don't know whether there were any reasons for not including the annotation on StateFlow at the time.
Would it be possible to add it? I sadly lack the technical knowledge in the relevant areas to contribute an implementation, especially since I don't know if the JS semantics would need to change when going from a cold to a hot flow.Dmitry Khalanskiy [JB]
10/28/2026, 10:18 AMMy understanding is that the compiler automatically falls back to the closest exported supertypeDid I get it right that this code
@JsExport
class MyClass(
val dateField: kotlinx.datetime.LocalDate
)
would export dateField as some opaque object with no fields, since kotlinx.datetime.LocalDate isn't marked with @JsExport? If so, this looks like a glaring usability issue that should be fixed on the side of Kotlin/JS. Otherwise, we'd be accepting that Kotlin library authors would need to annotate everything with @JsExport, which doesn't look like an even remotely viable approach to me. Neither Kotlin/Native nor Kotlin/JVM require annotating every single public API.Marc
10/28/2026, 10:33 AMdateField would get exported as any (or NonNullable<unknown> if -Xdts-use-unknown-instead-any is used), unless LocalDate also gets a @JsExport annotation on it. You get a partial export if a (hypothetical) supertype of LocalDate had the annotation, where the field gets exported as that supertype instead.
In this second case, JS code sees dateField as an instance of the supertype, and all the fields and methods defined on LocalDate itself are invisible to JS consumers (technically still present so Kotlin/JS code can use them, but with mangled names).
So with the current Kotlin/JS approach, my understanding is that the only way to fix it would be to add @JsExport to all types that might appear in public signatures and that should be directly exportable.Dmitry Khalanskiy [JB]
10/28/2026, 10:43 AM@JsExport, that's not at all difficult. What's stopping me from proceeding with this is my strong opinion that this approach needs to be reworked. I don't think we can realistically require third-party libraries to spam @JsExport everywhere, and as a first-party library, I'd prefer kotlinx.coroutines not to set a precedent.
@Filipp Zhinkin, could you please share your view of this issue (the last two messages should provide enough context)?Marc
10/28/2026, 10:45 AMStateFlow , but I understand if this is something you want to solve at a fundamental level instead.Dmitry Khalanskiy [JB]
10/28/2026, 10:48 AMArtem Kobzar
10/28/2026, 11:18 AMArtem Kobzar
10/28/2026, 11:44 AMFilipp Zhinkin
10/28/2026, 1:35 PM@Filipp Zhinkin, could you please share your view of this issue (the last two messages should provide enough context)?@Dmitry Khalanskiy [JB], here's a quick answer: I agree that the export should be improved and it seems inconvenient to explicitly export every single declaration someone needs to expose to Js/Ts. With that said, if we can solve a particular problem right now by simply adding an annotation, then it's worth doing it. If/when the export will be improved, we can always remove the annotation.
Dmitry Khalanskiy [JB]
10/30/2026, 10:20 AMIf/when the export will be improved, we can always remove the annotation.If that's actually the case, sure, there's no harm in annotating a couple of APIs with
JsExport. The linked issue youtrack.jetbrains.com/issue/KT-47200/KJS-IR-Define-exports-without-JsExport does not convince me that we should expect that. Let's continue the discussion there!Artem Kobzar
10/30/2026, 11:34 AMDmitry Khalanskiy [JB]
10/30/2026, 11:57 AMEdoardo Luppi
10/30/2026, 12:43 PMWe could of course annotate everything withDO NOT do this btw. This will result in unwanted transitive exports in all projects that import your library. It looks like a straightforward solution but the impact is huge and problematic, also in terms of unnecessarily retained code., that's not at all difficult@JsExport
Artem Kobzar
10/30/2026, 2:44 PMEdoardo Luppi
10/30/2026, 2:47 PM@JsExport specifically.