microsoft / microsoft/TypeScript
Proposal: The internal modifier for classes
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
The internal modifier
Often there is a need to share information on types within a program or package that should not be
accessed from outside of the program or package. While the public accessibility modifier allows
types to share information, is insufficient for this case as consumers of the package have access
to the information. While the private accessibility modifier prevents consumers of the package
from accessing information from the type, it is insufficient for this case as types within the
package also cannot access the information. To satisfy this case, we propose the addition of the
internal modifier to class members.
Goals
This proposal aims to describe the static semantics of the internal modifier as it applies to members of a class (methods, accessors, and properties).
Non-goals
This proposal does not cover any other use of the internal modifier on other declarations.
Static Semantics
Visibility
Within a non-declaration file, a class member marked internal is treated as if it had public
visibility for any property access:
source.ts:
class C {
internal x: number;
}
let c = new C();
c.x = 1; // ok
When consuming a class from a declaration file, a class member marked internal is treated as
if it had private visibility for any property access:
declaration.d.ts
class C {
internal x: number;
}
source.ts
/// <reference path="declaration.d.ts" />
let c = new C();
c.x = 1; // error
Assignability
When checking assignability of types within a non-declaration file, a class member marked
internal is treated as if it had public visibility:
source.ts:
class C {
internal x: number;
}
interface X {
x: number;
}
let x: X = new C(); // ok
If one of the types is imported or referenced from a declaration file, but the other is defined
inside of a non-declaration file, a class member marked internal is treated as if it had
private visibility:
declaration.d.ts
class C {
internal x: number;
}
source.ts
/// <reference path="declaration.d.ts" />
interface X {
}
let x: X = new C(); // error
It is important to allow assignability between super- and subclasses from a declaration file
with overridden members marked internal. When both types are imported or referenced from a
declaration file, a class member marked internal is treated as if it had protected visibility:
declaration.d.ts
class C {
internal x(): void;
}
class D extends C {
internal x(): void;
}
source.ts
/// <reference path="declaration.d.ts" />
let c: C = new D(); // ok
However, this does not carry over to subclasses that are defined in a non-declaration file:
declaration.d.ts
class C {
internal x(): void;
}
source.ts
/// <reference path="declaration.d.ts" />
class D extends C {
internal x(): void; // error
}
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提案の静的セマンティクスに関するセクションと、宣言ファイルおよび非宣言ファイルにおけるメンバーの可視性と代入可能性の例を調べます。完了条件は、オーバーライドされたメンバーと非宣言サブクラスの場合も含め、internal modifier が記載された public、private、protected のルールに従って一貫して動作することです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100