microsoft / microsoft/TypeScript

export access modifiers

Đang mở
#41,316 8 bình luận 79 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Awaiting More Feedback Suggestion
Ngôn ngữ chính
Go
Star
111k
Fork
14.4k
Merge trung bình
1 ngày 19 giờ
Pull request đã merge (30 ngày)
117

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách xem xét issue liên quan #321 và các ví dụ về access modifier trong issue này. Xác định cách kiểm tra quyền truy cập vào thư mục và scope lồng nhau đối với các import trực tiếp và import * as trước khi tìm các bài kiểm thử TypeScript compiler liên quan. Công việc được xem là hoàn thành khi các quy tắc được đề xuất đã được đặc tả và bao phủ bằng các bài kiểm thử mà không thay đổi JavaScript được phát ra.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
typescript
Lĩnh vực
compilers
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.