Skip to content

Translate playground example (3.8 breaking changes) into ja #797

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

Merged
merged 3 commits into from
Jul 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//// { compiler: { ts: "3.8.3" } }
// 以前のバージョンのTypeScriptでは、
// インデックスシグネチャを含む共用体に宣言されていないフィールドについて
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indexed typeの翻訳で、一般的に使用されていると思われるインデックスシグネチャとしました 🙇

Ref: TypeScript Deep Dive

// 型チェックが行われませんでした。

// インデックスシグネチャについてはこちら: example:indexed-types

// 例えば、以下のIdentifierCacheは、
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原文がTimingCacheとなっているのですが、文脈的にIdentifierCacheだと思われるので、変更しました。
What I'm wondering if I should fix this change on the original one 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確かにIdentifierCacheっぽいですね
もともとの方にPR送っていただけると 🙏

// オブジェクトのすべてのキーが、numberであることを表しています。

type IdentifierCache = { [key: string]: number };

// つまり、以下の例は型チェックエラーとなります。
// 'file_a'のキーにstringの値が設定されているためです。

const cacheWithString: IdentifierCache = { file_a: "12343" };

// しかし、IdentifierCacheを共用体に含めると、
// 以前は、型チェックが行われませんでした。

let userCache: IdentifierCache | { index: number };
userCache = { file_one: 5, file_two: "abc" };

// こちらが修正され、コンパイラーから
// 'file_two'のキーについてのエラーが出るようになりました。

// この型チェックは、キーの型が異なる場合も考慮に入れられています。
// 例: ([key: string] and [key: number])

type IdentifierResponseCache = { [key: number]: number };

let resultCache: IdentifierCache | IdentifierResponseCache;
resultCache = { file_one: "abc" };