File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
docs/playground/ko/3-8/Breaking Changes Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ //// { "compiler": { "ts": "3.8.3" } }
2+ // 이전 버전의 TypeScript에서
3+ // 검사기는 유니언의 선언되지 않은 필드가
4+ // 색인된 타입과 동일한지 확인하지 않았습니다.
5+
6+ // 여기에서 색인된 타입에 관해 배워볼 수 있습니다: example:indexed-types
7+
8+ // 예를 들어, 아래에 있는 IdentifierCache는
9+ // 객체에 있는 키가 숫자임을 보여줍니다:
10+
11+ type IdentifierCache = { [ key : string ] : number } ;
12+
13+ // 'file_a'가 문자열 값을 가지고 있어서
14+ // 실패를 의미합니다
15+
16+ const cacheWithString : IdentifierCache = { file_a : "12343" } ;
17+
18+ // 그러나, 유니언에 넣을 때는
19+ // 유효성 검사가 실행되지 않았습니다:
20+
21+ let userCache : IdentifierCache | { index : number } ;
22+ userCache = { file_one : 5 , file_two : "abc" } ;
23+
24+ // 이 부분은 고쳐졌고,
25+ // 컴파일러에서 'file_two'에 관한 오류가 발생합니다.
26+
27+ // 키가 다른 타입일 때도 고려합니다
28+ // 예를 들어: ([key: string] 그리고 [key: number])
29+
30+ type IdentifierResponseCache = { [ key : number ] : number } ;
31+
32+ let resultCache : IdentifierCache | IdentifierResponseCache ;
33+ resultCache = { file_one : "abc" } ;
You can’t perform that action at this time.
0 commit comments