-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Translate primitives any of playground examples into japanese #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,51 @@ | ||||||
// AnyはTypeScriptのエスケープ句です。 | ||||||
// any型を利用することで、一区切りのコードを | ||||||
// JavaScriptの様に動的に扱ったり、 | ||||||
// 型システムの制限を回避することができます。 | ||||||
|
||||||
// any型を利用する良いケースはJSON parsingです | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not confident here... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO: 「JSONのparseです」が良さそう There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここでのanyは推論されているものなので、「使用されている」のほうが自然かもしれません。
Suggested change
|
||||||
|
||||||
const myObject = JSON.parse("{}"); | ||||||
|
||||||
// TypeScriptにおけるAny宣言は、あなたがその値について詳しく知っていて | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// 安全なものなので信じてください、という宣言です。 | ||||||
// それが厳密に正しくない場合でも。例えば、次のコードはクラッシュします。 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO: 原文的にはこの並びなんですが、日本語としてはこなれていないので、ちょっと語順をいじるとこなれていい感じになると思います
|
||||||
|
||||||
myObject.x.y.z; | ||||||
|
||||||
// any型を利用することで、型安全のトレードオフと引き換えに、 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO: with the trade offで「引き換えに」になるのでトレードオフはなくても良さそう
Suggested change
|
||||||
// よりオリジナルに近いJavaScriptコードを書くことができます。 | ||||||
|
||||||
// any型は、(neverを除いて)どんな型でも割り当て可能であり、 | ||||||
// 一方の型をもう一方に割り当て可能にする「型のワイルドカード」 | ||||||
// によく似ています。 | ||||||
|
||||||
declare function debug(value: any); | ||||||
|
||||||
debug("a string"); | ||||||
debug(23); | ||||||
debug({ color: "blue" }); | ||||||
|
||||||
// いずれのdebug関数実行も、引数の型を | ||||||
// anyに置き換えることができるため許可されます。 | ||||||
|
||||||
// TypeScriptはany型の位置を考慮します。 | ||||||
// たとえば、この様なタプル型を利用した関数引数であってもです。 | ||||||
|
||||||
declare function swap(x: [number, string]): [string, number]; | ||||||
|
||||||
declare const pair: [any, any]; | ||||||
swap(pair); | ||||||
|
||||||
// swap関数引数であるnumber型・string型のペアは、 | ||||||
// any型のペアと置き換えることができるため、 | ||||||
// この関数実行は許可されます。 | ||||||
|
||||||
// タプル型が初見の場合、example:tuples を参照してください。 | ||||||
|
||||||
// unknown型はany型の兄弟とも言うことができますが、 | ||||||
// any型は「最善策を知っています」という場合に利用する一方で、 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO:
Suggested change
|
||||||
// unknown型は「最善策が分からないので、TSに型を伝える必要があります」 | ||||||
// という場合に利用します。 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO: |
||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [imo]原文はここに改行が無いので、それに合わせたいです。(原文に変更があった時にDiffをスムーズに受け入れられるように。)
Suggested change
|
||||||
// 詳細は example:unknown-and-never を参照してください。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyかanyか統一した方がいいかも?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any で統一しましょうか、実際にコードで使うのは
any
ですし