Script - Conditional Types


タイプは条件付きで使用できます.
interface Animal {
  live(): void;
  {
  interface Dog extends Animal {
    woof(): void;
  }
}

type Ex1 = Dog extends Animal ? number : string;
console.log(typeof Ex1) // number

type Ex2 = RegExp extends Animal ? number : string;
console.log(typeof RegExp) // string
条件タイプには次の条件があります.
	SomeType extends OtherType ? TrueType : FalseType;