See this code:
type BASE = { // ALSO WORKS FOR "BASE" AS Interface
base: "base"
}
interface OBJECT_A1 extends BASE {
propA: "propA"
}
type OBJECT_A2 = {
propA: "propA"
} & BASE
const a1: OBJECT_A1 = {propA: "propA", base: "base"}
const a2: OBJECT_A2 = {propA: "propA", base: "base"}
It works fine. Both approaches seem to work.
Is there any practical difference between "extending" an object by using interface X extends Y
and type X = X & Y
? When should I use one over the other?