2

I just want to define if two types are equals (strict). I suppose equality can be defined using the following type definition:

type EqualsType<T, U> = T extends U ? true : (U extends T ? true : false)

Now, suppose we have two type definitions:

type User = {
    readonly id: number,
    name: string
}

type UserReadOnly = Readonly<User>

In theory, the following assertion should be false:

type ResultSecondReadOnly = EqualsType<UserReadOnly, User>

I cannot understand how conditional type definition works in this case.

  • TypeScript uses a structural type system, and the `readonly` modifier does not affect the structure of your object, only its behavior. – Karol Majewski Feb 17 '19 at 02:15
  • 1
    https://stackoverflow.com/questions/52443276/how-to-exclude-getter-only-properties-from-type-in-typescript/52473108#52473108 – Titian Cernicova-Dragomir Feb 17 '19 at 06:50
  • While the other question is phrased differently, the underlying issue is the same and the answers are almost exactly what you'd want to see here, so I'm closing this is a duplicate. – jcalz Feb 17 '19 at 15:14

0 Answers0