microsoft / microsoft/TypeScript
Intersection for same key read-only property maybe wrong
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
### 🔎 Search Terms
Intersection readonly property
### 🕗 Version & Regression Information
- This changed between versions 4.4.4 and 4.5.5 (But all versions have errors)
### ⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.4.5#code/FAFwngDgpgBAgjAvDA3jA1gLhgOwK4C2ARlAE4wC+oksAQkqjKVAIYAmA9jgDZgbb5iZSsGAAKFBRgsAzvBgAyGLQCUAOnQMADAG5xk6XPpK46zcl2jw0GAFkW6KAHVSASxAsi3KAB4AKgB8DGgAtMzsXLwwANoA0jCuOBhQYBwAZjB+ALrYfnFZlHqiVjQwAMIM9o4u7p7ePrQBehJSsuVm2s0GbRVKqhqd+q1Giu0DFkVAA
### 💻 Code
```ts
type A = { k: number }
type B = { readonly k: number }
({} as A & B).k = 0;
({} as B & A).k = 0;
type MakeWritable = { -readonly [K in keyof T]: T[K] };
type C = MakeWritable;
({} as C).k = 0;
({} as C & B).k = 0;
({} as B & C).k = 0;
```
### 🙁 Actual behavior
command:
```
z:\webdl\test>tsc --target esnext --lib esnext test.ts
```
output:
```
test.ts:15:15 - error TS2540: Cannot assign to 'k' because it is a read-only property.
15 ({} as C & B).k = 0;
~
test.ts:16:15 - error TS2540: Cannot assign to 'k' because it is a read-only property.
16 ({} as B & C).k = 0;
~
Found 2 errors in the same file, starting at: test.ts:15
```
### 🙂 Expected behavior
no error.
### Additional information about the issue
_No response_
贡献指南
调研方向
先从 Playground 链接和 `test.ts` 重现开始,然后运行所示的 `tsc --target esnext --lib esnext test.ts` 命令。跟踪 TypeScript 的 checker 如何处理交叉类型和 readonly 属性;当两个 `C` 交叉类型赋值能够在没有 TS2540 的情况下编译,同时重现仍得到覆盖时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100