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

Typescript: Component declaration reference is not recognized by parser

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

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

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
react, typescript
Lĩnh vực
devtools

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện vấn đề trong playground của react-docgen với Language được đặt thành Typescript, sử dụng mẫu .tsx và gọi reactDocgen.parse() trên tham chiếu khai báo. Truy dấu điểm vào của parser đối với các khai báo .d.ts và so sánh kết quả với đầu ra mong đợi, trong đó Component2 được bao gồm cùng với mô tả, displayName, methods và props của nó.

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

Mô tả

typescript

Description

Many Typescript libraries publish types in declaration files (.d.ts) alongside their associated .js bundles. In .d.ts files generated through TS compilation, function types are often defined using declaration references, such as:

declare const MyComponent: React.FunctionComponent<ComponentProps>;

Currently declaration references are not recognized by reactDocgen.parse(). When react-docgen parses a .d.ts file with a single declaration reference, it emits an error: Error: No suitable component definition found..

Desired Behavior

The following code:

import * as React from 'react';

interface ComponentProps {
  foo: string;
}

/**
 * My component is so darn cool!
 */
const Component1: React.FunctionComponent<ComponentProps> = () => <div />;

/**
 * Mine too!
 */
declare const Component2: React.FunctionComponent<ComponentProps>;

Results in the following output:

[
  {
    "description": "My component is so darn cool!",
    "displayName": "Component1",
    "methods": [],
    "props": {
      "foo": {
        "required": true,
        "tsType": {
          "name": "string"
        },
        "description": ""
      }
    }
  },
  {
    "description": "Mine too!",
    "displayName": "Component2",
    "methods": [],
    "props": {
      "foo": {
        "required": true,
        "tsType": {
          "name": "string"
        },
        "description": ""
      }
    }
  }
]

Actual Behavior

The same code results in the following output:

[
  {
    "description": "My component is so darn cool!",
    "displayName": "Component1",
    "methods": [],
    "props": {
      "foo": {
        "required": true,
        "tsType": {
          "name": "string"
        },
        "description": ""
      }
    }
  }
]

Steps to Reproduce

Paste the .tsx sample code from the "Expected Behavior" section into the react-docgen playground with Language set to Typescript.

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.