I have been diving into the world of typescript and I encountered a challenge with the syntax of union types, specifically when using a generic interface:
interface ArrayElementError {
kind: 'failure'
reason: string
}
interface ArrayElementSuccess<T> {
kind: 'success'
value: T
}
type ArrayElement = ArrayElementError | ArrayElementSuccess
// or interface ArrayElement<T extends ArrayEmementError | ArrayElementSuccess> {}
When I tried to compile the code above, I received an error message:
TSError: ⨯ Unable to compile TypeScript:
Could someone please guide me on the correct syntax for extending two generic interfaces (or creating a new type using the type keyword)?