microsoft / microsoft/TypeScript
Better ownership lint to eliminate ownership chaos for generated code
- 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ả
### 🔍 Search Terms
- proposal-explicit-resource-management
- ownership
- lifetime
### ✅ Viability Checklist
- [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
- [x] This wouldn't change the runtime behavior of existing JavaScript code
- [x] This could be implemented without emitting different JS based on the types of the expressions
- [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- [x] This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- [x] This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
### ⭐ Suggestion
Better ownership lint to kill ownership chaos.
Maybe rust lifetime?
### 📃 Motivating Example
See
https://github.com/denoland/deno/issues/34953
Typescript should lint below code will crash due to ownership
```js
Deno.serve({}, async (_req) => {
using file = await Deno.open(new URL(import.meta.url).pathname);
return new Response(file.readable);
});
```
https://github.com/denoland/deno/issues/34953#issuecomment-4636526241
Some think
> `file.readable` carries ownership of the file
https://github.com/denoland/deno/issues/34953#issuecomment-4636588109
Some think `file.readable` does not carries ownership of the file
```js
> file.readable[Symbol.dispose]
undefined
```
### 💻 Use Cases
1. What do you want to use this for?
Better ownership type
2. What shortcomings exist with current approaches?
TBD
3. What workarounds are you using in the meantime?
No way.
## related
https://github.com/denoland/deno/issues/34931
Simple code leads to server crash due to ownership
Genered by AI.
Simplified for reproduce.
```ts
Deno.serve({}, async (_req) => {
using file = await Deno.open(new URL(import.meta.url).pathname);
return new Response(file.readable);
});
```
---
https://github.com/denoland/deno/issues/34953
How to easy stream file within deno server?
---
https://github.com/tc39/proposal-explicit-resource-management/issues/274
How does proposal-explicit-resource-management suggest how to easy extend stream file lifetime within server?
---
https://github.com/microsoft/TypeScript/issues/63540
Better ownership lint to kill ownership chaos
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu với các ví dụ về ownership trong issue này và so sánh các issue Deno được liên kết với issue 274 của TC39 proposal-explicit-resource-management. Yêu cầu này không xác định các tệp TypeScript, các test hay một lint rule cụ thể, và các phần về những thiếu sót cùng workaround vẫn đang TBD. Một đề xuất hoàn chỉnh sẽ cần xác định mô hình ownership, các chẩn đoán và hành vi dự kiến trước khi có thể bắt đầu triển khai.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, 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
- Ít trao đổi
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 18/100