microsoft / microsoft/TypeScript
export access modifiers
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
Search Terms
export access modifiers public protected private
Related: #321
Suggestion
Allow adding public, protected and private access modifiers to export statements. This would limit where the data can be imported from.
Access Modifiers
private
Other file in the same directory scope have access to the export.
protected
Other file in the same directory scope or a nested scope have access to the export.
public (default)
Current behavior - Can be access from anywhere.
Use Cases
Most useful for large projects - allows modules to limit where things they expose are used.
Examples
Given the following director structure:
.
├── module
│ ├── submodule
│ │ └── index.ts
│ ├── file.ts
│ └── index.ts
└── index.ts
// module/file.ts
public export const foo = "hello";
protected export const bar = "world";
private export const baz = "!!!";
// module/submodule/index.ts
import { foo, bar, baz } from '../file';
// ^^^ Cannot access baz as is private.
// module/index.ts
import { foo, bar, baz } from './file'; // All Ok.
// index.ts
import { foo, bar, baz } from './module/file';
// ^^^ Cannot access bar as is protected.
// ^^^ Cannot access baz as is private.
Note: If using import * as X from ..., X's type simply wouldn't include things it doesn't have access to.
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず関連する issue #321 と、この issue にあるアクセス修飾子の例を確認します。関連する TypeScript コンパイラのテストを探す前に、直接インポートと import * as について、ディレクトリおよびネストしたスコープへのアクセスをどのようにチェックするかを定義します。提案したルールが仕様化され、出力される JavaScript を変更せずにテストでカバーされれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100