Flattened Error Reporting
TypeScript의 오류 메시지는 가끔 필요 이상으로 상세할 수 있습니다...
3.7 버전에서, 몇 가지 터무니없는 사례를 보실 수 있습니다.
중첩 속성
// 이전에는, 중첩된 속성 당 두 줄의 코드였기에,
오류 메시지의 첫 번째와 마지막 줄을 읽음으로써
빠르게 오류 메시지를 읽는 방법을 배웠습니다.
이제는 인라인입니다:
3.6 버전에서는 다음과 같습니다:
Type '{ b: { c: { d: { e: number; }; }; }; }' is not assignable to type '{ b: { c: { d: { e: string; }; }; }; }'.
Types of property 'b' are incompatible.
Type '{ c: { d: { e: number; }; }; }' is not assignable to type '{ c: { d: { e: string; }; }; }'.
Types of property 'c' are incompatible.
Type '{ d: { e: number; }; }' is not assignable to type '{ d: { e: string; }; }'.
Types of property 'd' are incompatible.
Type '{ e: number; }' is not assignable to type '{ e: string; }'.
Types of property 'e' are incompatible.
Type 'number' is not assignable to type 'string'
유용하고 간결한 오류 메시지를 제공하여,
객체의 여러 타입을 통해 작업을 처리할 수 있습니다.
let a = { b: { c: { d: { e: "string" } } } };
let b = { b: { c: { d: { e: 12 } } } };
a = b;
// 3.6 버전에서는 다음과 같습니다:
Type '{ a: { b: { c: { d: { e: { f: typeof OtherClass; }; }; }; }; }; }' is not assignable to type '{ a: { b: { c: { d: { e: { f: typeof ExampleClass; }; }; }; }; }; }'.
Types of property 'a' are incompatible.
Type '{ b: { c: { d: { e: { f: typeof OtherClass; }; }; }; }; }' is not assignable to type '{ b: { c: { d: { e: { f: typeof ExampleClass; }; }; }; }; }'.
Types of property 'b' are incompatible.
Type '{ c: { d: { e: { f: typeof OtherClass; }; }; }; }' is not assignable to type '{ c: { d: { e: { f: typeof ExampleClass; }; }; }; }'.
Types of property 'c' are incompatible.
Type '{ d: { e: { f: typeof OtherClass; }; }; }' is not assignable to type '{ d: { e: { f: typeof ExampleClass; }; }; }'.
Types of property 'd' are incompatible.
Type '{ e: { f: typeof OtherClass; }; }' is not assignable to type '{ e: { f: typeof ExampleClass; }; }'.
Types of property 'e' are incompatible.
Type '{ f: typeof OtherClass; }' is not assignable to type '{ f: typeof ExampleClass; }'.
Types of property 'f' are incompatible.
Type 'typeof OtherClass' is not assignable to type 'typeof ExampleClass'.
Type 'OtherClass' is not assignable to type 'ExampleClass'.
Types of property 'state' are incompatible.
Type 'number' is not assignable to type 'string'
class ExampleClass {
state = "ok";
}
class OtherClass {
state = 12;
}
let x = { a: { b: { c: { d: { e: { f: ExampleClass } } } } } };
let y = { a: { b: { c: { d: { e: { f: OtherClass } } } } } };
x = y;