Skip to content

Commit d283509

Browse files
committed
Translate 1 file to ko. playground Indexed Types
1 parent 9d9d733 commit d283509

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
// 새로운 이름을 지어서 생성됩니다.

0 commit comments

Comments
 (0)