microsoft / microsoft/TypeScript

Suggestion: Derive disposability checks from known symbols rather than global interfaces

Đang mở
#62,121 0 bình luận 3 reaction 1 người được giao Xem trên GitHub

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

Experimentation Needed Suggestion
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

### Acknowledgement

- [x] I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

### Comment

When it comes to checking for disposability (for use with `using`/`await using` declarations), the checker fetches the global `Disposable`/`AsyncDisposable` symbol and runs an assignability test against its type.

This is mostly fine, but this interface is user-mutable, so any script in the project which plays with these interfaces can unintentionally modify the checker's behaviour. For example, a module might declare an empty global interface for backwards compatibility:
```ts
declare global {
interface Disposable {}
}

export interface MyResource extends Disposable {
...
}
```
...which means that all disposability tests will now return true within the checker, if there's no lib.esnext.disposable or similar to populate the interface.

Other checker processes that rely on well-known symbols tend to interrogate the symbol-keyed properties directly, rather than test against global types – for example, iteration checks first fetch the well-known `Symbol.iterator` via `getPropertyNameForKnownSymbolName`, then use this index to access the iteration method on the target type.

While not critical, it would be an improvement if the checker could test against the `Symbol.dispose`/`Symbol.asyncDispose` properties directly, rather than testing for assignability against the global interface.

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.

Đánh giá

Issue này chưa được đánh giá.

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.