제네릭
function add<T>(x: T, y: T): T { return x + y;}
타입을 함수 선언 할 때 말고 사용할 때 정함
function add(x: string | number, y: string | nuymber): string | number {return x + y};
//이런 함수를
function add<T extends number | string>(x: T, y: T): T {return x + y};
// extends 는 제네릭에 제한을 줄 수 있다. (부분집합같은)
// <T extends {...}>
// <T extends any[]>
// <T extends (...args: any) => any>
// <T extends abstract new (...args: any) => any> //생성자
add(1 ,2) // 3
add('1', '2') // '12'
const add = <T = unknown>(x: Y, y: T) => ({x, y})
const add = <T,>(x: Y, y: T) => ({x, y})