From cca3fea6940bcaa7e226820aa585d8880c72cc0a Mon Sep 17 00:00:00 2001 From: Cristopher Namchee Date: Fri, 9 Oct 2020 08:15:41 +0700 Subject: [PATCH 1/5] docs(i18n-id): Provide Indonesian translation for Named Tuples --- .../id/4-0/New TS Features/Named Tuples.ts | 55 +++++++++++++++++++ .../4-0/New TS Features/Unknown in Catch.ts | 37 +++++++++++++ .../id/4-0/New TS Features/Variadic Tuples.ts | 54 ++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 packages/playground-examples/copy/id/4-0/New TS Features/Named Tuples.ts create mode 100644 packages/playground-examples/copy/id/4-0/New TS Features/Unknown in Catch.ts create mode 100644 packages/playground-examples/copy/id/4-0/New TS Features/Variadic Tuples.ts diff --git a/packages/playground-examples/copy/id/4-0/New TS Features/Named Tuples.ts b/packages/playground-examples/copy/id/4-0/New TS Features/Named Tuples.ts new file mode 100644 index 000000000000..f160a2eefdfa --- /dev/null +++ b/packages/playground-examples/copy/id/4-0/New TS Features/Named Tuples.ts @@ -0,0 +1,55 @@ +//// { compiler: { ts: "4.0.2" } } + +// _Tuple_ adalah _array_ dimana urutan elemennya penting bagi +// sistem tipe, Anda dapat mempelajari lebih lanjut tentang _tuple_ +// di example:tuples. + +// Pada TypeScript versi 3.9, tipe dari sebuah _tuple_ mendapatkan +// kemampuan untuk memberikan nama pada elemen-elemen _array_. + +// Sebagai contoh, Anda biasanya menulis lokasi garis lintang +// dan garis bujur dalam sebuah _tuple_: + +type LokasiLama = [number, number] + +const lokasi: LokasiLama[] = [ + [40.7144, -74.006], + [53.6458, -1.785] +] + +// Cara penulisan tersebut menyebabkan Anda kesulitan untuk membedakan +// nilai garis lintang dan garis bujur, sehingga Anda biasanya akan +// menamai _tuple_ tersebut sebagai LintangBujur. + +// Pada TypeScript versi 4.0, Anda dapat menulis: + +type LokasiBaru = [lintang: number, bujur: number] + +const lokasiBaru: LokasiBaru[] = [ + [52.3702, 4.8952], + [53.3498, -6.2603] +] + +// Nama-nama yang telah dinyatakan pada _tuple_ akan muncul +// di editor ketika Anda menyorot angka 0 dan 1 pada akhir +// baris selanjutnya. +const lintangPertama = lokasiBaru[0][0] +const bujurPertama = lokasiBaru[0][1] + +// Walaupun terkesan tidak berguna, tujuan utama dari fitur +// tersebut adalah menjamin bahwa informasi tidak hilang +// ketika bekerja dengan sistem tipe. Sebagai contoh, ketika +// mengekstrak parameter dari sebuah fungsi menggunakan +// tipe perkakas `Parameter`: + +function pindahkanKeTengahPeta(bujur: number, lintang: number) { } + +// Pada TypeScript versi 4.0, cara penulisan ini tetap +// menyimpan informasi bujur dan lintang. +type parameterPindahkanKeTengahPeta = Parameters + +// Pada TypeScript versi 3.9, tipe di atas akan ditulis sebagai: +type parameterLamaPindahkanKeTengahPeta = [number, number] + +// Hal tersebut membuat beberapa manipulasi tipe yang rumit +// kehilangan informasi mengenai informasi parameter. diff --git a/packages/playground-examples/copy/id/4-0/New TS Features/Unknown in Catch.ts b/packages/playground-examples/copy/id/4-0/New TS Features/Unknown in Catch.ts new file mode 100644 index 000000000000..a1bf5322c263 --- /dev/null +++ b/packages/playground-examples/copy/id/4-0/New TS Features/Unknown in Catch.ts @@ -0,0 +1,37 @@ +//// { compiler: { ts: "4.0.2" } } + +// Karena JavaScript memperbolehkan kesalahan untuk melempar +// nilai apapun, TypeScript tidak mendukung deklarasi tipe +// dari sebuah kesalahan. + +try { + // .. +} catch (e) { } + +// Historically, this has meant that the `e` in the catch +// would default to any. This allowed for the freedom to +// arbitrarily access any property. With 4.0, we've loosened +// the restrictions on type assignment in the catch clause +// to allow both `any` and `unknown`. + +// Same behavior with any: +try { + // .. +} catch (e) { + e.stack; +} + +// Explicit behavior with unknown: + +try { + // .. +} catch (e) { + // You cannot use `e` at all until the type + // system learns what it is, for more info see: + // example:unknown-and-never + e.stack; + + if (e instanceof SyntaxError) { + e.stack; + } +} diff --git a/packages/playground-examples/copy/id/4-0/New TS Features/Variadic Tuples.ts b/packages/playground-examples/copy/id/4-0/New TS Features/Variadic Tuples.ts new file mode 100644 index 000000000000..c65c5c333092 --- /dev/null +++ b/packages/playground-examples/copy/id/4-0/New TS Features/Variadic Tuples.ts @@ -0,0 +1,54 @@ +//// { compiler: { ts: "4.0.2" } } +// Variadic Tuples gives tuples the ability to handle the rest operator (...) +// to pass types through type checker in a way that works like generics. + +// This is quite an advanced topic, so if you get lost do not worry too much. +// It builds on example:generic-functions and example:tuples + +// To start off, here is a variadic tuple which will always prefix another +// tuple with a number: + +type AddMax = [max: number, ...rest: T]; +// ^ Generic used to constrain the T +// ^ ... used to indicate where to merge + +// This can then be used for composition: +type MaxMin = AddMax<[min: number]> +type MaxMinDiameter = AddMax<[min: number, diameter: number]> + +// The same can be used after the tuple: +type SuffixDIContext = [...first: T, context: any]; +type DIContainer = SuffixDIContext<[param: string]> + +// This mechanism can be combined with multiple input params. For example, This +// function merges two arrays but uses '\0' as a sigil to indicate where the arrays +// start and stop. +function joinWithNullTerminators(t: [...T], u: [...U]) { + return ['\0', ...t, '\0', ...u, '\0'] as const; +} + +// TypeScript can infer the return type of a function like this: +const result = joinWithNullTerminators(['variadic', 'types'], ["terminators", 3]); + +// +// These tools make it possible to correctly type a function like curry which +// is a well used concept in functional programming: + +function curry(f: (...args: [...T, ...U]) => R, ...a: T) { + return (...b: U) => f(...a, ...b); +} + +// There are three generic arguments: +// - T: The params which are array of inputs to the curry function +// - U: The parameters which _aren't_ passed into to curry function, and need applying to the return func +// - R: the return type of the passed in function + +const sum = (left: number, right: number,) => left + right + +const a = curry(sum, 1, 2) +const b = curry(sum, 1)(2) +const c = curry(sum)(1, 2) + +// You can find a more indepth explanation, with more code samples in +// https://github.com/microsoft/TypeScript/pull/39094 + From b8a5928d99cc8ff0028fe6b6045bc5a275a8196e Mon Sep 17 00:00:00 2001 From: Cristopher Namchee Date: Fri, 9 Oct 2020 13:09:44 +0700 Subject: [PATCH 2/5] docs(i18n-id): Provide Indonesian translation for Unknown in Catch --- .../4-0/New TS Features/Unknown in Catch.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/playground-examples/copy/id/4-0/New TS Features/Unknown in Catch.ts b/packages/playground-examples/copy/id/4-0/New TS Features/Unknown in Catch.ts index a1bf5322c263..65501639f3fc 100644 --- a/packages/playground-examples/copy/id/4-0/New TS Features/Unknown in Catch.ts +++ b/packages/playground-examples/copy/id/4-0/New TS Features/Unknown in Catch.ts @@ -8,27 +8,29 @@ try { // .. } catch (e) { } -// Historically, this has meant that the `e` in the catch -// would default to any. This allowed for the freedom to -// arbitrarily access any property. With 4.0, we've loosened -// the restrictions on type assignment in the catch clause -// to allow both `any` and `unknown`. +// Secara historis, hal tersebut menandakan bahwa `e` dalam +// blok `catch` akan dianggap sebagai `any`. Anggapan tersebut +// memberikan kebebasan untuk mengakses properti apapun. +// Pada TypeScript versi 4.0, kami telah melonggarkan +// batasan pada pernyataan tipe pada klausa `catch` sehingga +// tipe `any` dan `unknown` merupakan tipe yang valid. -// Same behavior with any: +// Perilaku yang sama dengan `any`: try { // .. } catch (e) { e.stack; } -// Explicit behavior with unknown: +// Perilaku eksplisit dengan `unknown`: try { // .. } catch (e) { - // You cannot use `e` at all until the type - // system learns what it is, for more info see: - // example:unknown-and-never + // Anda tidak dapat menggunakan `e` sama sekali + // sampai sistem tipe mengetahui tipe dari `e`. + // Anda dapat mempelajari lebih lanjut mengenai + // hal tersebut melalui example:unknown-and-never. e.stack; if (e instanceof SyntaxError) { From 65ada78de6bef011240b32551d7d22e86f61512e Mon Sep 17 00:00:00 2001 From: Cristopher Namchee Date: Fri, 9 Oct 2020 16:42:05 +0700 Subject: [PATCH 3/5] docs(i18n-id): Provide Indonesian translation for variadic tuples --- .../id/4-0/New TS Features/Variadic Tuples.ts | 58 +++++++++++-------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/packages/playground-examples/copy/id/4-0/New TS Features/Variadic Tuples.ts b/packages/playground-examples/copy/id/4-0/New TS Features/Variadic Tuples.ts index c65c5c333092..898279d761f9 100644 --- a/packages/playground-examples/copy/id/4-0/New TS Features/Variadic Tuples.ts +++ b/packages/playground-examples/copy/id/4-0/New TS Features/Variadic Tuples.ts @@ -1,47 +1,58 @@ //// { compiler: { ts: "4.0.2" } } -// Variadic Tuples gives tuples the ability to handle the rest operator (...) -// to pass types through type checker in a way that works like generics. -// This is quite an advanced topic, so if you get lost do not worry too much. -// It builds on example:generic-functions and example:tuples +// _Variadic tuples_ memberikan kemampuan pada _tuple_ untuk menangani +// operator _rest_ (...) untuk memberikan tipe pada pemeriksa tipe +// dengan cara yang mirip dengan tipe generik. -// To start off, here is a variadic tuple which will always prefix another -// tuple with a number: +// _Variadic tuples_ merupakan topik yang rumit, sehingga Anda tidak perlu +// khawatir bila Anda merasa kebingungan. Contoh di bawah berdasarkan +// example:generic-functions dan example:tuples. -type AddMax = [max: number, ...rest: T]; -// ^ Generic used to constrain the T -// ^ ... used to indicate where to merge +// Sebagai permulaan, di bawah ini merupakan sebuah _variadic tuple_ yang +// akan selalu memberikan prefiks pada _tuple_ lain dengan sebuah bilangan: -// This can then be used for composition: +type AddMax = [max: number, ...rest: T]; +// ^ Tipe generik digunakan untuk +// membatasi T +// ^ Operator `...` digunakan +// untuk mengetahui letak +// penggabungan + +// Tipe di atas dapat digunakan untuk komposisi: type MaxMin = AddMax<[min: number]> type MaxMinDiameter = AddMax<[min: number, diameter: number]> -// The same can be used after the tuple: +// Hal yang sama juga digunakan setelah penggunaan _tuple_: type SuffixDIContext = [...first: T, context: any]; type DIContainer = SuffixDIContext<[param: string]> -// This mechanism can be combined with multiple input params. For example, This -// function merges two arrays but uses '\0' as a sigil to indicate where the arrays -// start and stop. +// Mekanisme ini dapat digabungkan dengan banyak parameter masukan. +// Sebagai contoh, fungsi di bawah ini menggabungkan dua buah _array_ +// namun menggunakan '\0' sebagai karakter yang menjadi tanda +// dimana _array_ dimulai dan berakhir. function joinWithNullTerminators(t: [...T], u: [...U]) { return ['\0', ...t, '\0', ...u, '\0'] as const; } -// TypeScript can infer the return type of a function like this: +// TypeScript dapat menyimpilkan tipe kembalian dari sebuah fungsi +// seperti berikut: const result = joinWithNullTerminators(['variadic', 'types'], ["terminators", 3]); // -// These tools make it possible to correctly type a function like curry which -// is a well used concept in functional programming: +// Perkakas ini memungkinkan kita untuk memberi tipe +// pada sebuah fungsi seperti fungsi untuk _currying_ +// yang merupakan sebuah konsep yang sering digunakan +// pada pemrograman fungsional: function curry(f: (...args: [...T, ...U]) => R, ...a: T) { return (...b: U) => f(...a, ...b); } -// There are three generic arguments: -// - T: The params which are array of inputs to the curry function -// - U: The parameters which _aren't_ passed into to curry function, and need applying to the return func -// - R: the return type of the passed in function +// Ada 3 parameter generik: +// - T: Kumpulan masukan yang digunakan pada fungsi _curry_ +// - U: Kumpulan masukan yang tidak digunakan pada fungsi +// _curry_, dan harus diteruskan pada fungsi yang dikembalikan +// - R: Tipe kembalian dari fungsi yang diberikan const sum = (left: number, right: number,) => left + right @@ -49,6 +60,7 @@ const a = curry(sum, 1, 2) const b = curry(sum, 1)(2) const c = curry(sum)(1, 2) -// You can find a more indepth explanation, with more code samples in +// Anda dapat mempelajari lebih lanjut tentang _variadic tuples_, +// beserta dengan contoh kode programnya pada: // https://github.com/microsoft/TypeScript/pull/39094 - + From f2de791616cf1eb87468a2c5a8fdd3b363b5acab Mon Sep 17 00:00:00 2001 From: Cristopher Namchee Date: Fri, 9 Oct 2020 18:51:36 +0700 Subject: [PATCH 4/5] docs(i18n-id): Fix menyimpilkan typo --- .../copy/id/4-0/New TS Features/Variadic Tuples.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/playground-examples/copy/id/4-0/New TS Features/Variadic Tuples.ts b/packages/playground-examples/copy/id/4-0/New TS Features/Variadic Tuples.ts index 898279d761f9..3db4eb29c69f 100644 --- a/packages/playground-examples/copy/id/4-0/New TS Features/Variadic Tuples.ts +++ b/packages/playground-examples/copy/id/4-0/New TS Features/Variadic Tuples.ts @@ -34,7 +34,7 @@ function joinWithNullTerminators(t: [. return ['\0', ...t, '\0', ...u, '\0'] as const; } -// TypeScript dapat menyimpilkan tipe kembalian dari sebuah fungsi +// TypeScript dapat menyimpulkan tipe kembalian dari sebuah fungsi // seperti berikut: const result = joinWithNullTerminators(['variadic', 'types'], ["terminators", 3]); From 14fec48aa0e1f426566187657e4ac3bd32eeb9c8 Mon Sep 17 00:00:00 2001 From: Cristopher Namchee Date: Fri, 9 Oct 2020 19:37:03 +0700 Subject: [PATCH 5/5] docs(i18n-id): Rephrase translation to avoid context loss --- .../copy/id/4-0/New TS Features/Named Tuples.ts | 2 +- .../copy/id/4-0/New TS Features/Unknown in Catch.ts | 8 ++++---- .../copy/id/4-0/New TS Features/Variadic Tuples.ts | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/playground-examples/copy/id/4-0/New TS Features/Named Tuples.ts b/packages/playground-examples/copy/id/4-0/New TS Features/Named Tuples.ts index f160a2eefdfa..281d3554db5e 100644 --- a/packages/playground-examples/copy/id/4-0/New TS Features/Named Tuples.ts +++ b/packages/playground-examples/copy/id/4-0/New TS Features/Named Tuples.ts @@ -36,7 +36,7 @@ const lokasiBaru: LokasiBaru[] = [ const lintangPertama = lokasiBaru[0][0] const bujurPertama = lokasiBaru[0][1] -// Walaupun terkesan tidak berguna, tujuan utama dari fitur +// Walaupun terkesan sangat sederhana, tujuan utama dari fitur // tersebut adalah menjamin bahwa informasi tidak hilang // ketika bekerja dengan sistem tipe. Sebagai contoh, ketika // mengekstrak parameter dari sebuah fungsi menggunakan diff --git a/packages/playground-examples/copy/id/4-0/New TS Features/Unknown in Catch.ts b/packages/playground-examples/copy/id/4-0/New TS Features/Unknown in Catch.ts index 65501639f3fc..c66cb0a408e5 100644 --- a/packages/playground-examples/copy/id/4-0/New TS Features/Unknown in Catch.ts +++ b/packages/playground-examples/copy/id/4-0/New TS Features/Unknown in Catch.ts @@ -1,8 +1,8 @@ //// { compiler: { ts: "4.0.2" } } -// Karena JavaScript memperbolehkan kesalahan untuk melempar -// nilai apapun, TypeScript tidak mendukung deklarasi tipe -// dari sebuah kesalahan. +// Dikarenakan JavaScript memperbolehkan untuk menggunakan +// tipe data apapun, TypeScript tidak mendukung +// deklarasi tipe data pada sebuah galat (`Error()`) try { // .. @@ -28,7 +28,7 @@ try { // .. } catch (e) { // Anda tidak dapat menggunakan `e` sama sekali - // sampai sistem tipe mengetahui tipe dari `e`. + // sampai sistem tipe data mengetahui tipe data dari `e`. // Anda dapat mempelajari lebih lanjut mengenai // hal tersebut melalui example:unknown-and-never. e.stack; diff --git a/packages/playground-examples/copy/id/4-0/New TS Features/Variadic Tuples.ts b/packages/playground-examples/copy/id/4-0/New TS Features/Variadic Tuples.ts index 3db4eb29c69f..630964c8603e 100644 --- a/packages/playground-examples/copy/id/4-0/New TS Features/Variadic Tuples.ts +++ b/packages/playground-examples/copy/id/4-0/New TS Features/Variadic Tuples.ts @@ -1,8 +1,8 @@ //// { compiler: { ts: "4.0.2" } } // _Variadic tuples_ memberikan kemampuan pada _tuple_ untuk menangani -// operator _rest_ (...) untuk memberikan tipe pada pemeriksa tipe -// dengan cara yang mirip dengan tipe generik. +// operator _rest_ (...) untuk memberikan tipe data pada pemeriksa tipe +// data dengan cara yang mirip dengan tipe generik. // _Variadic tuples_ merupakan topik yang rumit, sehingga Anda tidak perlu // khawatir bila Anda merasa kebingungan. Contoh di bawah berdasarkan @@ -18,7 +18,7 @@ type AddMax = [max: number, ...rest: T]; // untuk mengetahui letak // penggabungan -// Tipe di atas dapat digunakan untuk komposisi: +// Tipe data di atas dapat digunakan untuk komposisi: type MaxMin = AddMax<[min: number]> type MaxMinDiameter = AddMax<[min: number, diameter: number]> @@ -34,12 +34,12 @@ function joinWithNullTerminators(t: [. return ['\0', ...t, '\0', ...u, '\0'] as const; } -// TypeScript dapat menyimpulkan tipe kembalian dari sebuah fungsi -// seperti berikut: +// TypeScript dapat menyimpulkan tipe data kembalian dari sebuah +// fungsi seperti berikut: const result = joinWithNullTerminators(['variadic', 'types'], ["terminators", 3]); // -// Perkakas ini memungkinkan kita untuk memberi tipe +// Perkakas ini memungkinkan kita untuk memberi tipe data // pada sebuah fungsi seperti fungsi untuk _currying_ // yang merupakan sebuah konsep yang sering digunakan // pada pemrograman fungsional: