|
| 1 | +//// { compiler: { }, order: 3 } |
| 2 | + |
| 3 | +// TypeScript의 오류 메시지는 가끔 필요 이상으로 상세할 수 있습니다... |
| 4 | +// 3.7 버전에서, 몇 가지 터무니없는 사례를 보실 수 있습니다. |
| 5 | + |
| 6 | +// 중첩 속성 |
| 7 | + |
| 8 | +let a = { b: { c: { d: { e: "string" } } } }; |
| 9 | +let b = { b: { c: { d: { e: 12 } } } }; |
| 10 | + |
| 11 | +a = b; |
| 12 | + |
| 13 | +// 이전에는, 중첩된 속성 당 두 줄의 코드였기에, |
| 14 | +// 오류 메시지의 첫 번째와 마지막 줄을 읽음으로써 |
| 15 | +// 빠르게 오류 메시지를 읽는 방법을 배웠습니다. |
| 16 | + |
| 17 | +// 이제는 인라인입니다: |
| 18 | + |
| 19 | +// 3.6 버전에서는 다음과 같습니다: |
| 20 | +// |
| 21 | +// Type '{ b: { c: { d: { e: number; }; }; }; }' is not assignable to type '{ b: { c: { d: { e: string; }; }; }; }'. |
| 22 | +// Types of property 'b' are incompatible. |
| 23 | +// Type '{ c: { d: { e: number; }; }; }' is not assignable to type '{ c: { d: { e: string; }; }; }'. |
| 24 | +// Types of property 'c' are incompatible. |
| 25 | +// Type '{ d: { e: number; }; }' is not assignable to type '{ d: { e: string; }; }'. |
| 26 | +// Types of property 'd' are incompatible. |
| 27 | +// Type '{ e: number; }' is not assignable to type '{ e: string; }'. |
| 28 | +// Types of property 'e' are incompatible. |
| 29 | +// Type 'number' is not assignable to type 'string' |
| 30 | + |
| 31 | +// 유용하고 간결한 오류 메시지를 제공하여, |
| 32 | +// 객체의 여러 타입을 통해 작업을 처리할 수 있습니다. |
| 33 | + |
| 34 | +class ExampleClass { |
| 35 | + state = "ok"; |
| 36 | +} |
| 37 | + |
| 38 | +class OtherClass { |
| 39 | + state = 12; |
| 40 | +} |
| 41 | + |
| 42 | +let x = { a: { b: { c: { d: { e: { f: ExampleClass } } } } } }; |
| 43 | +let y = { a: { b: { c: { d: { e: { f: OtherClass } } } } } }; |
| 44 | +x = y; |
| 45 | + |
| 46 | +// 3.6 버전에서는 다음과 같습니다: |
| 47 | +// |
| 48 | +// Type '{ a: { b: { c: { d: { e: { f: typeof OtherClass; }; }; }; }; }; }' is not assignable to type '{ a: { b: { c: { d: { e: { f: typeof ExampleClass; }; }; }; }; }; }'. |
| 49 | +// Types of property 'a' are incompatible. |
| 50 | +// Type '{ b: { c: { d: { e: { f: typeof OtherClass; }; }; }; }; }' is not assignable to type '{ b: { c: { d: { e: { f: typeof ExampleClass; }; }; }; }; }'. |
| 51 | +// Types of property 'b' are incompatible. |
| 52 | +// Type '{ c: { d: { e: { f: typeof OtherClass; }; }; }; }' is not assignable to type '{ c: { d: { e: { f: typeof ExampleClass; }; }; }; }'. |
| 53 | +// Types of property 'c' are incompatible. |
| 54 | +// Type '{ d: { e: { f: typeof OtherClass; }; }; }' is not assignable to type '{ d: { e: { f: typeof ExampleClass; }; }; }'. |
| 55 | +// Types of property 'd' are incompatible. |
| 56 | +// Type '{ e: { f: typeof OtherClass; }; }' is not assignable to type '{ e: { f: typeof ExampleClass; }; }'. |
| 57 | +// Types of property 'e' are incompatible. |
| 58 | +// Type '{ f: typeof OtherClass; }' is not assignable to type '{ f: typeof ExampleClass; }'. |
| 59 | +// Types of property 'f' are incompatible. |
| 60 | +// Type 'typeof OtherClass' is not assignable to type 'typeof ExampleClass'. |
| 61 | +// Type 'OtherClass' is not assignable to type 'ExampleClass'. |
| 62 | +// Types of property 'state' are incompatible. |
| 63 | +// Type 'number' is not assignable to type 'string' |
0 commit comments