Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Support extracting of type information from tagged templates

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

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
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
react, typescript
Lĩnh vực
documentation

Hướng nghiên cứu

Bắt đầu trong src/utils/getTypeAnnotation.js, tại phần tra cứu type annotation được liên kết trong issue, sau đó so sánh AST TaggedTemplateExpression được hiển thị với các node hiện đang được xử lý. Theo dõi cách react-docgen-annotation-resolver sử dụng kết quả. Hoàn thành khi các định nghĩa type như FlexProps được trích xuất từ ví dụ styled-components.

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

Mô tả

It looks like even if I have a resolver that resolves to components that use tagged templates like styled-components, the type annotations aren't extracted.

Consider the following example:

import styled from "styled-components";

interface FlexProps {
    bool: boolean
}

const Flex = styled('div')<FlexProps>`
	display: flex;
`;

/** @component */
export default Flex;

When used with an react-docgen-annotation-resolver, the type definitions won't be extracted.

I scoped it to this place in code that's responsible for finding type annotations: https://github.com/okonet/react-docgen/blob/8fb401089e3fe2b38d41638bc5690436e23aceb3/src/utils/getTypeAnnotation.js#L22

and it looks like it's searching for specific key typeAnnotation in the AST. For styled-component example, though, it won't present. But what's going to present is

Node {
     type: 'TaggedTemplateExpression',
     start: 95,
     end: 138,
     loc: SourceLocation { start: [Position], end: [Position] },
     tag:
      Node {
        type: 'CallExpression',
        start: 95,
        end: 108,
        loc: [SourceLocation],
        callee: [Node],
        arguments: [Array] },
     quasi:
      Node {
        type: 'TemplateLiteral',
        start: 119,
        end: 138,
        loc: [SourceLocation],
        expressions: [],
        quasis: [Array] },
     typeParameters:
      Node {
        type: 'TSTypeParameterInstantiation',
        start: 108,
        end: 119,
        loc: [SourceLocation],
        params: [Array] } },

So, it looks like there is something related to types in there but its not being properly handled.

Does anyone has any pointers on how to fix it?

Ngôn ngữ chính
TypeScript
Star
3.8k
Fork
316
Merge trung bình
3 giờ 28 phút
Pull request đã merge (30 ngày)
6

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.

Issue khác của reactjs/react-docgen

Tất cả issue của reactjs/react-docgen

Issue tương tự

Thêm issue về TypeScript

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.