microsoft / microsoft/TypeScript

Extend createMethodSignature and updateMethodSignature with 'modifiers' argument

Đang mở
#35,959 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Domain: API In Discussion Suggestion
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ả

Search Terms

updateMethodSignature, createMethodSignature

Suggestion

It should be possible to provide an array of Modifiers (or undefined) to the createMethodSignature and updateMethodSignature functions.

Use Cases

When using the TypeScript compiler APIs, TypeScript provides numerous create and update functions that can be used to generate an AST, for example from Custom Transformers. However, for MethodSignatures, which may have modifiers such as the static keyword, there's no option to create or update their modifiers. This breaks one of my libraries which sole purpose is to simply deep-clone a TypeScript node. A workaround is to manually patch the modifiers, however I hope this can be part of the function (as it is for others, like createPropertySignature and updatePropertySignature).

Examples

import {createMethodSignature, createNodeArray, createModifier, SyntaxKind} from "typescript";

createMethodSignature(
    createNodeArray([
        createModifier(SyntaxKind.StaticKeyword)
    ]),
    node.typeParameters,
    node.parameters,
    node.type,
    node.name,
    node.questionToken
);

However, the above example would be a breaking change since the first parameter expects a NodeArray of type parameters, so an alternative solution would be to accept it as the last argument.

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách kiểm tra các định nghĩa và phần triển khai của TypeScript Compiler API cho createMethodSignature và updateMethodSignature, so sánh chúng với createPropertySignature và updatePropertySignature. Xác định một thiết kế đối số modifiers không gây breaking change, sau đó xác minh rằng các lệnh gọi hiện có vẫn hợp lệ và các method signature có thể được tạo hoặc cập nhật với modifiers.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
typescript
Lĩnh vực
compilers
Loại issue
Tính năng
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.