I'm using a custom made State class to store result but seems compiler is complaining about the different types
Does anyone know any workaround for this?
Code in 🧵
flamy
07/16/2024, 1:15 PM
Copy code
sealed interface UiState<out T> {
data class Success<T>(val value: T) : UiState<T>
data class Error(val exception: Throwable? = null, val message: String = ""): UiState<Nothing>
data object Loading : UiState<Nothing>
}
.map { UiState.Success(it) as UiState<List<File>> }
Otherwise,
map
thinks that the new flow type must be
UiState.Success
, as that's the most specific type it can infer. You can let it know that you want a less specific type.
gratitude thank you 1
f
flamy
07/16/2024, 1:25 PM
@Dmitry Khalanskiy [JB] it works, but IDE thinks it's a useless cast ðŸ«
c
Chrimaeon
07/16/2024, 3:09 PM
it
in
catch
is a exception so you are not emitting a UIState with list as declared in the return type
r
Rok Oblak
07/16/2024, 3:14 PM
you can also specify the generic type at that map call to make it clear you want UIState and not UIState.Success, otherwise it will infer the most specific type at that point which is Success