1

Typescript playground

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?

cbdeveloper
  • 27,898
  • 37
  • 155
  • 336

0 Answers0