feat(tree): typescript/strong typing of nodes
- Ngôn ngữ chính
- TypeScript
- Star
- 25k
- Fork
- 6.8k
- Merge trung bình
- 1 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 91
Mô tả
### Feature Description
Currently `*matTreeNodeDef` types the resulting variable as `any`:

### Use Case
>enable you to build web apps with confidence!
The lack of strong typing is really problematic for bigger projects, and it feels like a downgrade in developer experience compared to custom build trees.
Further motivation for this has been described in:
https://github.com/angular/components/issues/16273
https://github.com/angular/angular/issues/28731
https://nartc.me/blog/typed-mat-cell-def/
https://github.com/angular/components/issues/22290
Workaround copied from https://github.com/angular/components/issues/22290:
```ts
import { Directive, input } from '@angular/core';
import { MatTree, MatTreeNodeDef } from '@angular/material/tree';
@Directive({
selector: '[matTreeNodeDef]',
providers: [
{ provide: MatTreeNodeDef, useExisting: TypeSafeMatTreeNodeDefDirective },
],
})
export class TypeSafeMatTreeNodeDefDirective extends MatTreeNodeDef<
NoInfer
> {
readonly matTreeNodeDefTree = input.required>();
static ngTemplateContextGuard(
dir: TypeSafeMatTreeNodeDefDirective,
ctx: any,
): ctx is { $implicit: T; index: number } {
return true;
}
}
```
```diff
-
+
...
-
+
```
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu với các entry point MatTreeNodeDef, MatTree và matTreeNodeDef được nêu trong issue, sau đó so sánh workaround TypeSafeMatTreeNodeDefDirective được liên kết và các cuộc thảo luận được tham chiếu. Được xem là hoàn tất khi biến được khai báo bởi *matTreeNodeDef có kiểu mạnh mà không cần workaround, đồng thời cách sử dụng tree được ghi trong tài liệu vẫn hoạt động.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- angular, typescript
- Lĩnh vực
- developer-experience, frontend
- 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
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100