Skip to content

Latest commit

 

History

History
68 lines (56 loc) · 1.46 KB

Union_extract_excloude.md

File metadata and controls

68 lines (56 loc) · 1.46 KB

문제

image

풀이

// Extract<T, U> 는 T와 U가 공유하는 타입들을 추출합니다.
type type1 = string | number | boolean;
type type2 = number | boolean;

type commonType = Extract<type1, type2>; // number | boolean

// (구성요소 뽑아내기) 풀이
import {Equal, Expect} from "../../helper";

export type Event =
    | {
    type: "click";
    event: MouseEvent;
}
    | {
    type: "focus";
    event: FocusEvent;
}
    | {
    type: "keydown";
    event: KeyboardEvent;
};

type ClickEvent = Extract<Event, {type: 'click'}>;

type tests = [Expect<Equal<ClickEvent, { type: "click"; event: MouseEvent }>>];

문제

image

풀이

import { Equal, Expect } from '../../helper';

export type Event =
  | {
      type: 'click';
      event: MouseEvent;
    }
  | {
      type: 'focus';
      event: FocusEvent;
    }
  | {
      type: 'keydown';
      event: KeyboardEvent;
    };

type NonKeyDownEvents = Exclude<Event, { type: 'keydown' }>;

// keydown과 click, focus를 포함해야함. keydown은 포함하지 말아야함
type tests = [
  Expect<
    Equal<
      NonKeyDownEvents,
      | { type: 'click'; event: MouseEvent }
      | { type: 'focus'; event: FocusEvent }
    >
  >
];