When working with HTTP responses in TypeScript, I am interested in creating a variant type that can represent different states. In Rust, a similar type can be defined as:
enum Response<T> {
Empty,
Loading,
Failure(String),
Success(data: T),
}
In Kotlin, sealed classes can achieve the same concept:
sealed class Response<out: T> {
object Empty: Response<Nothing>()
object Loading: Response<Nothing>()
class Failure(val err: string): Response<Nothing>()
class Success(val data: T): Response<T>
}
I wonder if there is a way to implement this variant type structure in TypeScript?