File tree Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change 1
- import { UnionCar , UnionMobile } from "./utils/data.interface" ;
1
+ //intersection types
2
2
3
- //속성이 많아 진다면 if문보다는 switch문으로 작성하는게 더 가독성이 높다.
4
- function getGift ( gift : UnionCar | UnionMobile ) {
5
- console . log ( gift . color ) ;
6
- if ( gift . name === "car" ) {
7
- gift . start ( ) ;
8
- } else {
9
- gift . call ( ) ;
10
- }
3
+ import { InterCar , InterToy } from "./utils/data.interface" ;
4
+
5
+ const toyCar : InterToy & InterCar = {
6
+ name : '타요' ,
7
+ start ( ) { } ,
8
+ color : 'blue' ,
9
+ price : 1000 ,
11
10
}
Original file line number Diff line number Diff line change @@ -61,4 +61,17 @@ export interface UnionMobile {
61
61
name : 'mobile' ;
62
62
color : string ;
63
63
call ( ) : void ;
64
+ }
65
+
66
+ //intersection types
67
+
68
+ export interface InterCar {
69
+ name : string ;
70
+ start ( ) : void ;
71
+ }
72
+
73
+ export interface InterToy {
74
+ name : string ;
75
+ color : string ;
76
+ price : number ;
64
77
}
You can’t perform that action at this time.
0 commit comments