microsoft / microsoft/TypeScript
refinement types
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
This is a further development of the idea of tag types.
There are situations where being able to encode a certain predicate about a given value using its type is tremendously helpful.
Let's imagine that we have a number. In order to proceed with it we need to assert that it is greater than 0. This assertion doesn't come for free, because it takes some processor time to get evaluated. Since numbers are immutable this assertion only needs to be evaluated once and will hold true from then on without having to be reevaluated. But due to having no way to attach this knowledge to the number value we:
- either need to play safe and reevaluate it every time immediately before using
- or take our chances trying to trace it through the code from the place where it was asserted keeping the result of the assertion in mind and hoping not to break things during the next refactoring
Being able to attach additional knowledge to the type of a value in form of predicate that is guaranteed to hold true as long as the value doesn't change is what is called refinement types.
@ahejlsberg, what are the chances of seeing the refinement types in TypeScript one day?
References:
- Refinement types: https://en.wikipedia.org/wiki/Refinement_(computing)
- Pre/post conditions, Hoare logic: https://en.wikipedia.org/wiki/Hoare_logic
- Design by contract: https://en.wikipedia.org/wiki/Design_by_contract
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先阅读 issue 的标签类型链接,以及其中关于 refinement types、Hoare logic 和 design by contract 的参考资料。该 issue 没有指定文件、测试或实现入口;要完成贡献,首先需要定义 TypeScript 设计,并确定已接受的 refinement types 范围。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 20/100