TypeScript - Conditional Types

CH_Hwang·2022년 3월 17일
0

TypeScript

목록 보기
6/12

타입을 조건적으로 사용할 수 있다.

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

conditional types는 다음과 같은 조건표현을 가진다

	SomeType extends OtherType ? TrueType : FalseType;

0개의 댓글