File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
docs/playground/ko/TypeScript/Meta-Types Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ // 타입을 복제하는 자신을 발견할 때가 있습니다.
2+ // 일반적인 예시는 자동으로 생성된
3+ // API 응답의 중첩된 자원입니다.
4+
5+ interface ArtworkSearchResponse {
6+ artists : {
7+ name : string ;
8+ artworks : {
9+ name : string ;
10+ deathdate : string | null ;
11+ bio : string ;
12+ } [ ] ;
13+ } [ ] ;
14+ }
15+
16+ // 이 인터페이스가 수작업으로 만들어졌다면
17+ // artworks를 인터페이스로 가져오는 것을 상상하기 쉽습니다:
18+
19+ interface Artwork {
20+ name : string ;
21+ deathdate : string | null ;
22+ bio : string ;
23+ }
24+
25+ // 그러나, 이 경우엔 API를 제어하지 않고
26+ // 인터페이스를 수작업으로 만들었다면
27+ // 응답을 변경할 때 ArtworkSearchResponse의 artworks 부분과
28+ // Artwork가 동기화되지 않을 수 있습니다.
29+
30+ // 이에 대한 해결책은 JavaScript가 문자열을 통해
31+ // 프로퍼티에 접근하는 방법을 복제하는 색인 된 타입입니다.
32+
33+ type InferredArtwork = ArtworkSearchResponse [ "artists" ] [ 0 ] [ "artworks" ] [ 0 ] ;
34+
35+ // InferredArtwork는 타입의 프로퍼티를 찾아보고
36+ // 색인한 하위집합에
37+ // 새로운 이름을 지어서 생성됩니다.
You can’t perform that action at this time.
0 commit comments