microsoft / microsoft/TypeScript
Design Meeting Notes, 2026-07-21
Chưa có ai nhận issue này.
- 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ả
# Strict `nil` Checking
* Lots of issues you can see from the new codebase by searching the repo for "nil dereference".
* Tools exist for static analysis in Go like [nilaway](https://github.com/uber-go/nilaway)
* However, we ended up with over 1000 errors which seemed like too many to address.
* One of the issues with nilaway is that it doesn't have a way of encoding invariants in the type system.
* For example:
```go
func IsParenthesizedTypeNode(node *Node) bool {
return node.Kind == SyntaxKind.ParenthesizedType
}
func SkipTypeParentheses(node *Node) *Node {
for IsParenthesizedTypeNode(node) {
node = node.Type()
}
return node
}
// Acts as a helper to just grab the `Type` property
// from various node types.
func (n *Node) Type() *Node {
switch n.Kind {
case SyntaxKind.ParenthesizedType:
return n.AsParenthesizedType().Type
// ...
}
```
* In that example, nilaway complains that `node` may be nil in the call to `node.Type()`, but we know that it can't be because of the invariant established by `IsParenthesizedTypeNode`.
* Back in TypeScript, we would just grab the property `node.type` because `IsParenthesizedTypeNode` would have been a type guard that would narrow the type of `node` to `ParenthesizedTypeNode`.
* Now we have a virtual call and nilaway can't link whatever we've learned from the call to `IsParenthesizedTypeNode`.
* So @gabritto has been prototyping a linting pass that is able to encode much of the same information from TypeScript's control flow analysis and type guards over our Go codebase.
* *\[\[ Example of it catching issues like https://github.com/microsoft/typescript-go/issues/1948 ]]*
* Uses comment suffixes.
```go
// Type alias that is purely for documentation purposes.
type CallExpressionNode = Node //ref: struct { Kind KindCallExpression; data DefPtr[CallExpression] }
// DefCallExpressionNode is a non-nilable pointer to a CallExpressionNode.
type DefCallExpressionNode = *CallExpressionNode //ref: nonnil
// A type guard:
//ref: node is DefCallExpressionNode
func IsCallExpression(node DefNode) bool {
return node.Kind == SyntaxKind.CallExpression
}
// A union type!
type NodeWithText = Node //ref: IdentifierNode | NumberLiteralNode
type DefNodeWithText = *NodeWithText //ref: nonnil
```
* Could we try to make the default non-nilable?
* Would probably make a lot of stuff less-specially-annotated.
* Would we be doing this checking on *all* types or just some subset of ours?
* All right now.
* Does this work well given that these are just aliases in Go?
* Go is good at preserving type aliases.
* How does this system know that something is a "discriminated union"?
* It's similar to what we do in TypeScript.
* We basically look for specific literal values in a common property across the set of types.
* Basically the comment format uses Go syntax for structs along with new syntax for unions.
* Looks extremely promising so far.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Không có tệp, bài kiểm thử hoặc điểm vào cụ thể nào được nêu. Hãy bắt đầu bằng việc xem lại phần thảo luận về kiểm tra nil nghiêm ngặt và định dạng hậu tố chú thích của prototype; để được coi là hoàn tất, cần quyết định phạm vi của lượt linting, các giá trị mặc định về nilability của nó, cũng như cách xử lý type guards và các union phân biệt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- go
- 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
- 30/100