|
| 1 | +//// { compiler: { }, order: 3 } |
| 2 | + |
| 3 | +// TypeScriptのエラーメッセージはときどき、少しだけ冗長になってしまうことがあります。 |
| 4 | +// 3.7では、特にひどいいくつかの事例を |
| 5 | +// 取り上げました。 |
| 6 | + |
| 7 | +// 入れ子のプロパティ |
| 8 | + |
| 9 | +let a = { b: { c: { d: { e: "string" } } } }; |
| 10 | +let b = { b: { c: { d: { e: 12 } } } }; |
| 11 | + |
| 12 | +a = b; |
| 13 | + |
| 14 | +// 以前は、入れ子のプロパティ1つにつき2行のコードでした。 |
| 15 | +// これは、エラーメッセージの最初と最後の行を読むことで、 |
| 16 | +// エラーメッセージの読み方をすぐに学べるということを意味していました。 |
| 17 | + |
| 18 | +// 今は、これらはインラインになりました。:tada: |
| 19 | + |
| 20 | +// 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 | +// これによって、様々な形のオブジェクトに対しても、 |
| 33 | +// 有用で簡潔なエラーメッセージを表示することができるようになりました。 |
| 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 | +// 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