From ac508b97d574df74096d3a901b559fa08a41dc57 Mon Sep 17 00:00:00 2001 From: takefumi-yoshii Date: Wed, 12 Feb 2020 14:29:13 +0900 Subject: [PATCH 1/5] copy file --- .../copy/ja/TypeScript/Primitives/Any.ts | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts diff --git a/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts b/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts new file mode 100644 index 000000000000..68258c5dca49 --- /dev/null +++ b/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts @@ -0,0 +1,50 @@ +// Any is the TypeScript escape clause. You can use any to +// either declare a section of your code to be dynamic and +// JavaScript like, or to work around limitations in the +// type system. + +// A good case for any is JSON parsing: + +const myObject = JSON.parse("{}"); + +// Any declares to TypeScript to trust your code as being +// safe because you know more about it. Even if that is +// not strictly true. For example, this code would crash: + +myObject.x.y.z; + +// Using an any gives you the ability to write code closer to +// original JavaScript with the trade-off of type safety. + +// any is much like a 'type wildcard' which you can replace +// with any type (except never) to make one type assignable +// to the other. + +declare function debug(value: any); + +debug("a string"); +debug(23); +debug({ color: "blue" }); + +// Each call to debug is allowed because you could replace the +// any with the type of the argument to match. + +// TypeScript will take into account the position of the +// anys in different forms, for example with these tuples +// for the function argument. + +declare function swap(x: [number, string]): [string, number]; + +declare const pair: [any, any]; +swap(pair); + +// The call to swap is allowed because the argument can be +// matched by replacing the first any in pair with number +// and the second `any` with string. + +// If tuples are new to you, see: example:tuples + +// Unknown is a sibling type to any, if any is about saying +// "I know what's best", then unknown is a way to say "I'm +// not sure what is best, so you need to tell TS the type" +// example:unknown-and-never From f74edbf17742aabe1d4daa89ad83834345f81729 Mon Sep 17 00:00:00 2001 From: takefumi-yoshii Date: Wed, 12 Feb 2020 14:29:48 +0900 Subject: [PATCH 2/5] translate into japanese --- .../copy/ja/TypeScript/Primitives/Any.ts | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts b/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts index 68258c5dca49..800c7c2c60df 100644 --- a/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts +++ b/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts @@ -1,24 +1,24 @@ -// Any is the TypeScript escape clause. You can use any to -// either declare a section of your code to be dynamic and -// JavaScript like, or to work around limitations in the -// type system. +// AnyはTypeScriptのエスケープ句です。 +// any型を利用することで、一区切りのコードを +// JavaScriptの様に動的に扱ったり、 +// 型システムの制限を回避することができます。 -// A good case for any is JSON parsing: +// any型を利用する良いケースはJSON parsingです const myObject = JSON.parse("{}"); -// Any declares to TypeScript to trust your code as being -// safe because you know more about it. Even if that is -// not strictly true. For example, this code would crash: +// TypeScriptにおけるAny宣言は、あなたがその値について +// 安全であることを知っているから信じてください、という宣言です。 +// それが厳密に正しくない場合でも。例えば、次のコードはクラッシュします。 myObject.x.y.z; -// Using an any gives you the ability to write code closer to -// original JavaScript with the trade-off of type safety. +// any型を利用することで、型安全のトレードオフと引き換えに、 +// よりオリジナルに近いJavaScriptコードを書くことができます。 -// any is much like a 'type wildcard' which you can replace -// with any type (except never) to make one type assignable -// to the other. +// any型は、どんな型でも(neverを除いた)割り当て可能であり、 +// 一方の型をもう一方に割り当て可能にする「型のワイルドカード」 +// によく似ています。 declare function debug(value: any); @@ -26,25 +26,26 @@ debug("a string"); debug(23); debug({ color: "blue" }); -// Each call to debug is allowed because you could replace the -// any with the type of the argument to match. +// いずれのdebug関数実行も、引数の型を +// anyに置き換えることができるため許可されます。 -// TypeScript will take into account the position of the -// anys in different forms, for example with these tuples -// for the function argument. +// TypeScriptはany型の位置を考慮します。 +// たとえば、この様なタプル型を利用した関数引数であってもです。 declare function swap(x: [number, string]): [string, number]; declare const pair: [any, any]; swap(pair); -// The call to swap is allowed because the argument can be -// matched by replacing the first any in pair with number -// and the second `any` with string. +// swap関数引数であるnumber型・string型のペアは、 +// any型のペアと置き換えることができるため、 +// この関数実行は許可されます。 -// If tuples are new to you, see: example:tuples +// タプル型が初見の場合、example:tuples を参照してください。 -// Unknown is a sibling type to any, if any is about saying -// "I know what's best", then unknown is a way to say "I'm -// not sure what is best, so you need to tell TS the type" -// example:unknown-and-never +// unknown型はany型の兄弟とも言うことができますが、 +// any型は「最善策を知っています」という場合に利用する一方で、 +// unknown型は「最善策が分からないので、TSに型を伝える必要があります」 +// という場合に利用します。 + +// 詳細は example:unknown-and-never を参照してください。 From 181121b24d52015d23ad7aa702b7d01f893df7d2 Mon Sep 17 00:00:00 2001 From: takefumi-yoshii Date: Wed, 12 Feb 2020 14:41:10 +0900 Subject: [PATCH 3/5] fix wording --- .../playground-examples/copy/ja/TypeScript/Primitives/Any.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts b/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts index 800c7c2c60df..3173e7a4aca1 100644 --- a/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts +++ b/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts @@ -7,8 +7,8 @@ const myObject = JSON.parse("{}"); -// TypeScriptにおけるAny宣言は、あなたがその値について -// 安全であることを知っているから信じてください、という宣言です。 +// TypeScriptにおけるAny宣言は、あなたがその値について詳しく知っていて +// 安全なものなので信じてください、という宣言です。 // それが厳密に正しくない場合でも。例えば、次のコードはクラッシュします。 myObject.x.y.z; From 724c588c8919b990d7f95b68a5c32c6f0cc9bc8a Mon Sep 17 00:00:00 2001 From: takefumi-yoshii Date: Thu, 13 Feb 2020 00:43:34 +0900 Subject: [PATCH 4/5] fix wording --- .../playground-examples/copy/ja/TypeScript/Primitives/Any.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts b/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts index 3173e7a4aca1..7b9560bec93f 100644 --- a/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts +++ b/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts @@ -16,7 +16,7 @@ myObject.x.y.z; // any型を利用することで、型安全のトレードオフと引き換えに、 // よりオリジナルに近いJavaScriptコードを書くことができます。 -// any型は、どんな型でも(neverを除いた)割り当て可能であり、 +// any型は、(neverを除いて)どんな型でも割り当て可能であり、 // 一方の型をもう一方に割り当て可能にする「型のワイルドカード」 // によく似ています。 From 21e63fef2160b3ecc555c5378ff165472ca5204b Mon Sep 17 00:00:00 2001 From: takefumi-yoshii Date: Thu, 13 Feb 2020 01:56:23 +0900 Subject: [PATCH 5/5] fix wording --- .../copy/ja/TypeScript/Primitives/Any.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts b/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts index 7b9560bec93f..9b57ce735082 100644 --- a/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts +++ b/packages/playground-examples/copy/ja/TypeScript/Primitives/Any.ts @@ -1,19 +1,19 @@ -// AnyはTypeScriptのエスケープ句です。 +// anyはTypeScriptのエスケープ句です。 // any型を利用することで、一区切りのコードを // JavaScriptの様に動的に扱ったり、 // 型システムの制限を回避することができます。 -// any型を利用する良いケースはJSON parsingです +// any型が使用されている良い例はJSON.parseの結果です const myObject = JSON.parse("{}"); -// TypeScriptにおけるAny宣言は、あなたがその値について詳しく知っていて -// 安全なものなので信じてください、という宣言です。 -// それが厳密に正しくない場合でも。例えば、次のコードはクラッシュします。 +// TypeScriptにおけるany宣言は、あなたがその値について詳しく知っていて +// それが厳密に正しくないとしても、安全なものなので信じてくださいという宣言です。 +// 例えば、次のコードはクラッシュします。 myObject.x.y.z; -// any型を利用することで、型安全のトレードオフと引き換えに、 +// any型を利用することで、型の安全性と引き換えに、 // よりオリジナルに近いJavaScriptコードを書くことができます。 // any型は、(neverを除いて)どんな型でも割り当て可能であり、 @@ -44,8 +44,7 @@ swap(pair); // タプル型が初見の場合、example:tuples を参照してください。 // unknown型はany型の兄弟とも言うことができますが、 -// any型は「最善策を知っています」という場合に利用する一方で、 -// unknown型は「最善策が分からないので、TSに型を伝える必要があります」 -// という場合に利用します。 - +// any型は「最善策を知っている」場合に利用する一方で、 +// unknown型は「最善策が分からないので、TSに型を伝える必要がある」 +// 場合に利用します。 // 詳細は example:unknown-and-never を参照してください。