File tree Expand file tree Collapse file tree 1 file changed +19
-20
lines changed Expand file tree Collapse file tree 1 file changed +19
-20
lines changed Original file line number Diff line number Diff line change 1
- // const ADMIN = 0;
2
- // const READ_ONLY = 1;
3
- // const AUTHOR = 2;
4
-
5
- enum Role {
6
- ADMIN = 5 , READ_ONLY = 'READ_ONLY' , AUTHOR = 100 //์ดํ๋ก๋ +1์ฉ ์ฆ๊ฐ๋ฅผ ํ๋ค.
7
- } ;
8
-
9
- const person = {
1
+ const person : {
2
+ name : string ,
3
+ age : number ,
4
+ hobbies : string [ ] ;
5
+ role : ( number | string ) [ ] ;
6
+ } = {
10
7
name : 'Maximilian' ,
11
8
age : 30 ,
12
9
hobbies : [ 'Sports' , 'Cooking' ] ,
13
- role : Role . ADMIN , //0
10
+ role : [ 2 , 'author' ]
14
11
} ;
15
12
16
- // person.role = Role.READ_ONLY;
17
- // error -> error TS2367: This comparison appears to be unintentional because the types 'Role.READ_ONLY' and 'Role.ADMIN' have no overlap.
18
- // ์์ธ : person.role์ด Role.READ_ONLY๋ก ์ค์ ๋ ํ, TypeScript๋ person.role์ด ๋ ์ด์ Role.ADMIN๊ณผ ๊ฐ์ ๊ฐ์ด ๋ ์ ์๋ค๊ณ ํ๋จํ๋ ๊ฒ
13
+ person . role . push ( 'admin' ) ;
14
+ person . role [ 1 ] = 10 ;
15
+ person . role = [ 0 , 'admin' , 'user' ] ;
16
+
17
+ //any๋ ์ด๋ค ํ์
์ด๋ ํ์ฉํ๋ ํ์
์ด๋ค. ์ด๋ป๊ฒ ๋ณด๋ฉด ์ ์ฐํ๋ค๊ณ ๋๊ปด์ง์ง์ง ๋ชจ๋ฅด๊ฒ ์ง๋ง ํ์
์คํฌ๋ฆฝํธ์ ์ฅ์ ์ ์ ํ ํ์ฉํ์ง ๋ชปํ๊ธฐ์ ์ข์ ๋ฐฉ๋ฒ์ ์๋๋ค.
18
+ let favoriteActivities : any [ ] ;
19
+ favoriteActivities = [ 'Sports' , 1 ] ; //์ด๋ ๊ฒ ๋ฐฐ์ด์ ๋ง๊ตฌ์ก์ด๋ก ์๋ก ๋ค๋ฅธ ํ์
์ ๋ฃ์ด๋ ์๋ฌด๋ฐ ์๋ฌ๊ฐ ์ผ์ด๋์ง ์๋๋ค.
20
+
21
+ console . log ( person . name ) ;
19
22
20
- if ( person . role === Role . ADMIN ) {
21
- console . log ( person . role ) ;
22
- } else if ( person . role === Role . READ_ONLY ) {
23
- console . log ( person . role ) ;
24
- } else if ( person . role === Role . AUTHOR ) {
25
- console . log ( person . role ) ;
26
- }
23
+ for ( const hobby of person . hobbies ) {
24
+ console . log ( hobby ) ;
25
+ }
You canโt perform that action at this time.
0 commit comments