|
| 1 | +//// { compiler: { }, order: 3 } |
| 2 | + |
| 3 | +// TypeScript's error messages can sometimes be a tad verbose... |
| 4 | +// With 3.7, we've taken a few cases which could be particularly |
| 5 | +// egregious. |
| 6 | + |
| 7 | +// Nested Properties |
| 8 | + |
| 9 | +let a = { b: { c: { d: { e: "string" } } } }; |
| 10 | +let b = { b: { c: { d: { e: 12 } } } }; |
| 11 | + |
| 12 | +a = b; |
| 13 | + |
| 14 | +// Before, it was 2 lines of code per nested property, which |
| 15 | +// quickly meant people learned to read error messages by |
| 16 | +// reading the first and then last line of an error message. |
| 17 | + |
| 18 | +// Now they're inline. :tada: |
| 19 | + |
| 20 | +// Previously in 3.6: |
| 21 | +// |
| 22 | +// Type '{ b: { c: { d: { e: number; }; }; }; }' is not assignable to type '{ b: { c: { d: { e: string; }; }; }; }'. |
| 23 | +// Types of property 'b' are incompatible. |
| 24 | +// Type '{ c: { d: { e: number; }; }; }' is not assignable to type '{ c: { d: { e: string; }; }; }'. |
| 25 | +// Types of property 'c' are incompatible. |
| 26 | +// Type '{ d: { e: number; }; }' is not assignable to type '{ d: { e: string; }; }'. |
| 27 | +// Types of property 'd' are incompatible. |
| 28 | +// Type '{ e: number; }' is not assignable to type '{ e: string; }'. |
| 29 | +// Types of property 'e' are incompatible. |
| 30 | +// Type 'number' is not assignable to type 'string' |
| 31 | + |
| 32 | +// This can handle working through different types of objects, |
| 33 | +// to still give a useful and concise error message. |
| 34 | + |
| 35 | +class ExampleClass { |
| 36 | + state = "ok"; |
| 37 | +} |
| 38 | + |
| 39 | +class OtherClass { |
| 40 | + state = 12; |
| 41 | +} |
| 42 | + |
| 43 | +let x = { a: { b: { c: { d: { e: { f: ExampleClass } } } } } }; |
| 44 | +let y = { a: { b: { c: { d: { e: { f: OtherClass } } } } } }; |
| 45 | +x = y; |
| 46 | + |
| 47 | +// Previously in 3.6: |
| 48 | +// |
| 49 | +// Type '{ a: { b: { c: { d: { e: { f: typeof OtherClass; }; }; }; }; }; }' is not assignable to type '{ a: { b: { c: { d: { e: { f: typeof ExampleClass; }; }; }; }; }; }'. |
| 50 | +// Types of property 'a' are incompatible. |
| 51 | +// Type '{ b: { c: { d: { e: { f: typeof OtherClass; }; }; }; }; }' is not assignable to type '{ b: { c: { d: { e: { f: typeof ExampleClass; }; }; }; }; }'. |
| 52 | +// Types of property 'b' are incompatible. |
| 53 | +// Type '{ c: { d: { e: { f: typeof OtherClass; }; }; }; }' is not assignable to type '{ c: { d: { e: { f: typeof ExampleClass; }; }; }; }'. |
| 54 | +// Types of property 'c' are incompatible. |
| 55 | +// Type '{ d: { e: { f: typeof OtherClass; }; }; }' is not assignable to type '{ d: { e: { f: typeof ExampleClass; }; }; }'. |
| 56 | +// Types of property 'd' are incompatible. |
| 57 | +// Type '{ e: { f: typeof OtherClass; }; }' is not assignable to type '{ e: { f: typeof ExampleClass; }; }'. |
| 58 | +// Types of property 'e' are incompatible. |
| 59 | +// Type '{ f: typeof OtherClass; }' is not assignable to type '{ f: typeof ExampleClass; }'. |
| 60 | +// Types of property 'f' are incompatible. |
| 61 | +// Type 'typeof OtherClass' is not assignable to type 'typeof ExampleClass'. |
| 62 | +// Type 'OtherClass' is not assignable to type 'ExampleClass'. |
| 63 | +// Types of property 'state' are incompatible. |
| 64 | +// Type 'number' is not assignable to type 'string' |
0 commit comments