microsoft / microsoft/TypeScript

Better ownership lint to eliminate ownership chaos for generated code

未关闭
#63,540 6 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Needs Proposal Suggestion
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

### 🔍 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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从此 issue 中的 ownership 示例开始,并将链接的 Deno issues 与 TC39 proposal-explicit-resource-management 的 issue 274 进行比较。该请求没有指出 TypeScript 文件、测试或具体的 lint rule,其缺点和 workaround 部分仍为 TBD。完整的提案需要在开始实现之前定义 ownership 模型、诊断信息和预期行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, typescript
领域
compilers
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
冷清
描述清晰度
需要澄清
新手友好度
18/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。