[TS] 타입 추론 및 타입 정의 연습
TIL
1. 타입 추론let a = 10;const b = 20;const c = [1, 2];const d = [1, "hello", true];const e = [1, 2, 3] as const;type A = number;type B = number;type C = number[];type D = (number | string | boolean)[];type E = [1, 2, 3]; 2. 조건을 만족하는 타입 정의- Animal 타입은 Dog 타입일수도 Cat 타입일수도 있다.- DogCat 타입은 Dog이자 Cat이다.type Dog = { name: string; color: string; };type Cat = { name: string; age: number; };​​type Animal = Do..
[TS] 대수 타입
TIL
대수 타입이란 여러개의 타입을 합성해서 만드는 타입을 말한다.합집합 (Union) 타입let a:" string | number | boolean;a = 1;a = "hello";a = true;유니온 타입으로 배열 타입 정의하기let arr: (number | string | boolean)[] = [1, "hello", true];유니온 타입과 객체 타입type Dog = { name: string; color: string;};type Person = { name: string; language: string;};type Union1 = Dog | Person;let union1: Union1 = { // ✅ name: "", color: "",};let union2: Union1 = {..