microsoft / microsoft/TypeScript
`readonly` mapped type modifiers for `Map` / `ReadonlyMap`
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
Search Terms
ReadonlyMap
ReadWrite
Writable
Suggestion
3.4.0-rc introduced the ability to use readonly mapped type modifiers with arrays.
(https://devblogs.microsoft.com/typescript/announcing-typescript-3-4-rc/)
It would be useful if the same syntax worked on
Use Cases
This is useful in any library dealing with immutable versions of types. It would allow mapped types to easily convert between Map and ReadonlyMap.
Examples
type ReadWrite<T> = { -readonly [P in keyof T]: T[P] };
const map: ReadWrite<ReadonlyMap<string, string>> = new Map();
map.put('a', 'c'); // this should work, since readonly has been removed.
type Readonly<T> = { readonly [P in keyof T]: T[P] };
const map: Readonly<Map<string, string>> = new Map();
map.put('a', 'c'); // this should not work, since readonly has been applied
Similar examples using Array instead of Map didn't work before 3.4 and did work afterwards.
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先重现 issue 中的 ReadWrite 和 Readonly 映射类型示例,并将它们的行为与 TypeScript 3.4 中引入的 Array 行为进行比较。跟踪编译器对映射类型的处理,以确定所需的设计;当 Map/ReadonlyMap 示例按指定方式运行且不改变生成的 JavaScript 时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100