I have a list of monotonous interfaces. Like this:
interface interface10 {
trackingId: string
status: string
payload: {
code: string
message: string
}
}
interface interface11 {
trackingId: string
status: string
payload: {
error: number
message: string
}
}
interface interface12 {
trackingId: string
status: string
payload: {
name: string
surname: string
age: number
}
}
interface interface13 {
trackingId: string
status: string
payload: {
name: string
data: number[]
labels: Date[]
}
}
I want to make one common interface with trackingId, status and payload:T as generic. How can I extend the interface and specify the payload type without creating additional interfaces? I only managed to do this:
interface IBase<T> {
trackingId: string
status: string
payload: T
}
interface payload1 {
code: string
message: string
}
interface interface14 extends IBase<payload1> {
// Eslint say that i should create at least 1 new property
what: string
}
export type interface15 = IBase<{
code: string
string: string
}>
The option with inheritance and redefinition of the payload is not suitable, it is necessary that the payload body is specified in the new interface. Something like below:
interface interface15 extends IBase<interface15> {
code: string
message: string
}
interface interface16 = IBase<{
code: string
message: string
}>