Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- angular modal
- summary
- 아이오닉 스크롤 이벤트
- 앵귤러 애니메이션
- 호버
- Angular Router
- 셀렉트박스 커스텀
- route
- modal
- Router
- 검색
- 옵저버블
- Oracle LISTAGG 사용 예시
- flex-1
- angular animation
- angular route
- 앵귤러 모달
- angular button
- egov spring ajax 사용 예시
- TAILWIND
- 스크롤 이벤트
- Ionic modal
- scroll
- prisma
- 모달
- ApexChart
- 스크롤 이벤트 감지
- formgroup
- mysql if
- ajax 사용 예시
Archives
- Today
- Total
깜놀하는 해므찌로
typescript Generic 활용 예시 본문
반응형
SMALL
/** Generic */
function getSize<T>(arr:T[]){ // TypeParameter 일반적으로 T 사용
return arr.length;
}
const arr1 = [1, 2, 3];
getSize<number>(arr1);
const arr2 = ["1", "2", "3"];
getSize<string>(arr2);
const arr3 = [true, false, true];
getSize(arr3); // 호출 시 제네릭 입력 생략 가능
/** 인터페이스 예시 */
interface Mobile<T>{
name : string;
price : number;
option : T;
}
const mobile1:Mobile<object> = {
name : "안드로이드",
price : 1000,
option : {
color : "red",
free : false
}
}
const mobile2:Mobile<string> = {
name : "아이폰",
price : 10000,
option : "greate"
}
interface User{
name:string;
age:number;
}
interface Car{
name:string;
color:string;
}
interface Book{
price:string;
}
const user:User = {
name : "이름",
age : 10
};
const car:Car = {
name : "Bmw",
color : "red"
}
const book:Book = {
price : "1000"
}
function showName<T extends {name:string}>(data:T):string{
return data.name;
}
showName(user);
showName(car);
showName(book);
반응형
LIST
'IT' 카테고리의 다른 글
typescript Utility 유틸리티 활용 예시 / keyof, partial, required, readonly, record, pick, omit, exclude, nonNullAble (0) | 2023.05.28 |
---|---|
ngFor speed controll 반복문 속도 조절 Directive 예시 (0) | 2023.05.27 |
Angular Animation condition 앵귤러 애니메이션 조건 예시 (0) | 2023.05.27 |
Error: Process completed with exit code 1. 배포 에러 해결 (0) | 2023.05.26 |
typescript abstract, extends 추상 클래스 활용 예시 (0) | 2023.05.26 |