Suggestion: ClassMethodDecoratorContext's name property could pick up Value["name"]
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, typescript
- Lĩnh vực
- compilers
Hướng nghiên cứu
Bắt đầu với định nghĩa ClassMethodDecoratorContext và so sánh kiểu tên có điều kiện được đề xuất với đặc tả ECMAScript Function.name. Sử dụng Playground được liên kết để kiểm tra các kết quả suy luận cho các trường hợp có tên và không có tên. Hoàn thành nghĩa là xác định được liệu thay đổi lib-definition được đề xuất có hợp lệ theo đặc tả hay không.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
lib Update Request
Configuration Check
My compilation target is ESNext and my lib is the default.
Missing / Incorrect Definition
interface ClassMethodDecoratorContext<
This = unknown,
Value extends (this: This, ...args: any) => any = (this: This, ...args: any) => any,
> {
// ...
/** The name of the decorated class element. */
readonly name: string | symbol;
// ...
We could change the name field to: readonly name: Value extends { name: string } ? Value["name"] : (string | symbol);. Most of the time, Value["name"] is just string, so this would be a non-breaking change (if slightly less intuitive).
However, if I were to augment my method type definitions to have a name property, TypeScript could pick up on it:
Sample Code
export type NumberStringType = {
repeatForward(s: string, n: number): string;
repeatBack(n: number, s: string): string;
};
type NST_RF_raw = NumberStringType["repeatForward"]["name"]
// ^? type NST_RF_raw = string
type MethodsOnlyType = {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
[key: string | number | symbol]: (...args: any[]) => any
}
type NamedMethodsOnlyType<T extends MethodsOnlyType> = {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
[Key in keyof T]: T[Key] & { name: Key }
}
type NST_RF_named = NamedMethodsOnlyType<NumberStringType>["repeatForward"]["name"];
// ^? type NST_RF_named = "repeatForward"
type DefaultInferredName = ClassMethodDecoratorContext<
// ^? type DefaultInferredName = string | symbol
NumberStringType, NamedMethodsOnlyType<NumberStringType>["repeatForward"]
>["name"];
interface ClassMethodDecoratorContext_Named<
This = unknown,
Value extends (this: This, ...args: any) => any = (this: This, ...args: any) => any,
> {
readonly name: Value extends { name: string } ? Value["name"] : (string | symbol);
}
type DirectName = ClassMethodDecoratorContext_Named<
// ^? type Directname = "repeatForward"
NumberStringType, NamedMethodsOnlyType<NumberStringType>["repeatForward"]
>["name"];
type InferredName = ClassMethodDecoratorContext_Named<
// ^? type InferredName = string
NumberStringType, NumberStringType["repeatForward"]
>["name"];
Motivation
I've been experimenting with method decorators for about a week now, to implement some aspect-oriented programming (or at least, my understanding of it). One facet I haven't yet cracked is removing the need for the method name on a decorator:
class NST_Class extends NumberStringClass {
@precondition<"repeatForward">(callForwardPre)
repeatForward(s: string, n: number): string {
return super.repeatForward(s, n);
}
}
Since the context has a name field of string | symbol type, I can't infer the name from that... I think.
I am perfectly willing to be wrong and have this whole ticket closed as invalid!
Documentation Link
The ECMAScript 2023 specification for Function.name says I'm possibly wrong here: it specifies the name field must be a string (specifically, "not a symbol"). This could be just a specification bug with the introduction of symbol keys, but I am not ready to assert that at this time.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.4k
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 117
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.
Issue khác của microsoft/TypeScript
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
microsoft/TypeScript#64322 · 2 bình luận · 1 reaction · 2 người được giao ·
-
Possible Improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/TypeScript#64278 · 1 bình luận · 1 reaction ·
-
Docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
microsoft/TypeScript#64118 · 1 bình luận ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
microsoft/TypeScript#64094 ·
-
Docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
microsoft/TypeScript#63959 · 5 bình luận ·
Tất cả issue của microsoft/TypeScript
Issue tương tự
-
optimization optimization:agents-md-curator
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
githubnext/gh-aw-cao#13143 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
blinklabs-io/bursa#904 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 bình luận ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100