Conversation
## 対象者 - [x] 📖 読者 ## Problem 「変性 (variance)」ページの「クラスの継承関係を使った例」セクションで、クラスの継承関係の説明が実際のコードと逆になっていました。 説明文は「`A`は`B`を継承し、`B`は`C`を継承しており」となっていましたが、直後のサンプルコードは `class B extends A`、`class C extends B` であり、実際は `B` が `A` を、`C` が `B` を継承しています。 このセクション以降の解説(「戻り値`C`は`B`のサブタイプなので」「引数`A`は`B`のスーパータイプなので」など)はコードどおりの継承関係を前提に書かれているため、読者は説明文とコード・解説のどちらが正しいのか判断できず、変性の理解に必要なサブタイプ/スーパータイプの向きを取り違えるおそれがありました。 ## Solution 説明文の継承関係をサンプルコードに合わせて修正しました。 ``` - `A`は`B`を継承し、`B`は`C`を継承しており、メソッドを追加しました。 + `B`は`A`を継承し、`C`は`B`を継承しており、それぞれメソッドを追加しました。 ``` なお、同ページの「ユニオン型を使った例」(`A = null` / `B = null | undefined` / `C = null | undefined | string`)はクラスの例とは逆に `A` が部分型ですが、本文中でその旨が明記されているため変更していません。 ## Value 読者がサンプルコードと説明文の食い違いに戸惑うことなく、`A`・`B`・`C` のサブタイプ関係を正しく理解した上で、共変・反変・不変の挙動を読み進められるようになります。 --- Close #1130
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
対象者
Problem
「変性 (variance)」ページの「クラスの継承関係を使った例」セクションで、クラスの継承関係の説明が実際のコードと逆になっていました。
説明文は「
AはBを継承し、BはCを継承しており」となっていましたが、直後のサンプルコードはclass B extends A、class C extends Bであり、実際はBがAを、CがBを継承しています。このセクション以降の解説(「戻り値
CはBのサブタイプなので」「引数AはBのスーパータイプなので」など)はコードどおりの継承関係を前提に書かれているため、読者は説明文とコード・解説のどちらが正しいのか判断できず、変性の理解に必要なサブタイプ/スーパータイプの向きを取り違えるおそれがありました。Solution
説明文の継承関係をサンプルコードに合わせて修正しました。
なお、同ページの「ユニオン型を使った例」(
A = null/B = null | undefined/C = null | undefined | string)はクラスの例とは逆にAが部分型ですが、本文中でその旨が明記されているため変更していません。Value
読者がサンプルコードと説明文の食い違いに戸惑うことなく、
A・B・Cのサブタイプ関係を正しく理解した上で、共変・反変・不変の挙動を読み進められるようになります。Close #1130