제네릭이란 타입을 마치 함수의 파라미터처럼 사용하는 것을 의미한다.
function test<T>(text:T) : T{ return text; }
const arr= Array<string> //Array안에 elem은 string이라는 거임.
type Todo= {text:string,completed:boolean} interface ComponentProps{todos:Array<Todo>} // todos의 타입은 Array이며, 배열 요소는 object의 Todo형식에 있는 // 2가지 key형태로 들어오며, text는 string, completed는 boolean이다.
interface ComponentProps{ name:string, age:number } const Component:React.FC<ComponentProps> = props => { return <div> <p>Name : {name}</p> <p>Age : {age}</p> <div> }
<div></div>
이다. 제네릭은 리턴값의 타입을 정의한다.