nodejs / nodejs/node

`FormData` implementation/types mismatch

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

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

Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.3k
Merge trung bình
4 ngày 2 giờ
Pull request đã merge (30 ngày)
283

Mô tả

Version

v22.6.0

Platform
Darwin esmbp2023 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:17:33 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6031 arm64
Subsystem

Fetch

What steps will reproduce the bug?

Regarding FormData type definition (https://github.com/nodejs/node/blob/main/deps/undici/src/types/formdata.d.ts):

The majority of methods are defined as instance methods (e.g., append, set, getAll, etc.):

// EXAMPLE
export declare class FormData {
  // ...
  append (name: string, value: unknown, fileName?: string): void
  // ...
}

But the following methods are defined as properties:

  • forEach
  • keys
  • values
  • entries
  • Symbol.iterator
// EXAMPLE
export declare class FormData {
  // ...
  forEach: (
    callbackfn: (value: FormDataEntryValue, key: string, iterable: FormData) => void,
    thisArg?: unknown
  ) => void
  // ...
}

This prevents extending those methods when extending FormData:

// EXAMPLE
class StrictFormData<T> extends FormData {
    /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/entries) */
    entries = <TK extends keyof T & string>(): IterableIterator<
        [TK, T[TK]]
    > => {
        // ERROR: TS2855: Class field entries defined by the parent class is not accessible in the child class via super.
        return super.entries() as IterableIterator<[TK, T[TK]]>;
    };
}
// EXAMPLE
class StrictFormData<T> extends FormData {
    /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/entries) */
    // ERROR: TS2425: Class FormData defines instance member property entries, but extended class StrictFormData<T> defines it as instance member function.
    entries<TK extends keyof T & string>(): IterableIterator<[TK, T[TK]]> {
        // ERROR: TS2855: Class field entries defined by the parent class is not accessible in the child class via super.
        return super.entries() as IterableIterator<[TK, T[TK]]>;
    }
}

Is it a mistake in the type definitions?

When looking at the implementation (https://github.com/nodejs/node/blob/main/deps/undici/src/lib/web/fetch/formdata.js) I don't see any of those methods added, neither "statically", nor dynamically upon construction. I might be missing something because exactly those atypically defined methods are the ones that I cannot find in the implementation.

Thanks!

How often does it reproduce? Is there a required condition?

See above.

What is the expected behavior? Why is that the expected behavior?

See above.

What do you see instead?

See above.

Additional information

See above.

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

So sánh deps/undici/src/types/formdata.d.ts với deps/undici/src/lib/web/fetch/formdata.js, tập trung vào forEach, keys, values, entries và Symbol.iterator. Tái hiện các lỗi subclassing của TypeScript trong issue và xác định xem các khai báo hay phần triển khai có khác với hành vi dự kiến hay không. Công việc được coi là hoàn tất khi các kiểu FormData và hành vi runtime nhất quán, đồng thời trường hợp mở rộng được báo cáo đã được xử lý.

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

Đánh giá

Công nghệ
javascript, nodejs, typescript
Lĩnh vực
api, backend
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
55/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.