|
| 1 | +//// { compiler: { }, order: 3 } |
| 2 | + |
| 3 | +// Pesan kesalahan yang ditampilkan TypeScript terkadang berlebihan. |
| 4 | +// Dengan TypeScript 3.7, kami telah mengambil beberapa kasus dimana |
| 5 | +// pesan kesalahan yang ditampilkan oleh TypeScript sangat buruk. |
| 6 | + |
| 7 | +// Properti bersarang |
| 8 | + |
| 9 | +let a = { b: { c: { d: { e: "string" } } } }; |
| 10 | +let b = { b: { c: { d: { e: 12 } } } }; |
| 11 | + |
| 12 | +a = b; |
| 13 | + |
| 14 | +// Sebelumnya, terdapat 2 baris kode untuk satu properti bersarang, |
| 15 | +// dimana orang-orang akan belajar untuk membaca pesan kesalahan |
| 16 | +// dengan membaca baris pertama terlebih dahulu dan kemudian |
| 17 | +// membaca baris terakhir. |
| 18 | + |
| 19 | +// Sekarang pesan kesalahan tersebut ditampilkan dalam satu baris. :tada: |
| 20 | + |
| 21 | +// Sebelumnya pada versi 3.6: |
| 22 | +// |
| 23 | +// Type '{ b: { c: { d: { e: number; }; }; }; }' is not assignable to type '{ b: { c: { d: { e: string; }; }; }; }'. |
| 24 | +// Types of property 'b' are incompatible. |
| 25 | +// Type '{ c: { d: { e: number; }; }; }' is not assignable to type '{ c: { d: { e: string; }; }; }'. |
| 26 | +// Types of property 'c' are incompatible. |
| 27 | +// Type '{ d: { e: number; }; }' is not assignable to type '{ d: { e: string; }; }'. |
| 28 | +// Types of property 'd' are incompatible. |
| 29 | +// Type '{ e: number; }' is not assignable to type '{ e: string; }'. |
| 30 | +// Types of property 'e' are incompatible. |
| 31 | +// Type 'number' is not assignable to type 'string' |
| 32 | + |
| 33 | +// Cara ini dapat menampilkan pesan kesalahan pada berbagai |
| 34 | +// tipe objek, namun tetap mampu untuk menampilkan |
| 35 | +// pesan kesalahan yang jelas dan berguna. |
| 36 | + |
| 37 | +class ContohKelas { |
| 38 | + state = "ok"; |
| 39 | +} |
| 40 | + |
| 41 | +class KelasLain { |
| 42 | + state = 12; |
| 43 | +} |
| 44 | + |
| 45 | +let x = { a: { b: { c: { d: { e: { f: ContohKelas } } } } } }; |
| 46 | +let y = { a: { b: { c: { d: { e: { f: KelasLain } } } } } }; |
| 47 | +x = y; |
| 48 | + |
| 49 | +// Sebelumnya pada versi 3.6: |
| 50 | +// |
| 51 | +// Type '{ a: { b: { c: { d: { e: { f: typeof KelasLain; }; }; }; }; }; }' is not assignable to type '{ a: { b: { c: { d: { e: { f: typeof ContohKelas; }; }; }; }; }; }'. |
| 52 | +// Types of property 'a' are incompatible. |
| 53 | +// Type '{ b: { c: { d: { e: { f: typeof KelasLain; }; }; }; }; }' is not assignable to type '{ b: { c: { d: { e: { f: typeof ContohKelas; }; }; }; }; }'. |
| 54 | +// Types of property 'b' are incompatible. |
| 55 | +// Type '{ c: { d: { e: { f: typeof KelasLain; }; }; }; }' is not assignable to type '{ c: { d: { e: { f: typeof ContohKelas; }; }; }; }'. |
| 56 | +// Types of property 'c' are incompatible. |
| 57 | +// Type '{ d: { e: { f: typeof KelasLain; }; }; }' is not assignable to type '{ d: { e: { f: typeof ContohKelas; }; }; }'. |
| 58 | +// Types of property 'd' are incompatible. |
| 59 | +// Type '{ e: { f: typeof KelasLain; }; }' is not assignable to type '{ e: { f: typeof ContohKelas; }; }'. |
| 60 | +// Types of property 'e' are incompatible. |
| 61 | +// Type '{ f: typeof KelasLain; }' is not assignable to type '{ f: typeof ContohKelas; }'. |
| 62 | +// Types of property 'f' are incompatible. |
| 63 | +// Type 'typeof KelasLain' is not assignable to type 'typeof ContohKelas'. |
| 64 | +// Type 'KelasLain' is not assignable to type 'ContohKelas'. |
| 65 | +// Types of property 'state' are incompatible. |
| 66 | +// Type 'number' is not assignable to type 'string' |
0 commit comments