2016-08-27 6 views

답변

5

기본적으로 함수가 참조하는 제네릭 목록이 있으며 해당 제네릭 목록 내에서 한 유형이 다른 유형을 참조하여 두 일반 유형 간의 관계를 정의 할 수 있음을 의미합니다.

function someFunction <T, U> (t: T, u: U): T { 
    return t; 
} 

const dog = someFunction(new Dog(), new Cat()); 

만세!

function someFunction <T extends U, U> (t: T, u: U): T { 
    return t; 
} 

const dog = someFunction(new Dog(), new Pet()); 
const cow = someFunction(new Cow(), new Animal()); 
const BOOM = someFunction(new Cat(), new Dog()); // *BEWM!* 
:

이제 경계 제네릭, 그들은 서로가 관계의 경계를 정의하기 위해 서로를 참조 할

관련 문제