`TextEncoder.encode` is typed `Uint8Array<ArrayBufferLike>` in workers-types; it returns a non-shared buffer
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 72/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- cpp, typescript
- Lĩnh vực
- api
Hướng nghiên cứu
Khai báo cần thay đổi là TextEncoder.encode, kiểu của nó được sinh từ các binding C++ trong src/workerd/api/encoding.h. Hãy dùng JSG_TS_OVERRIDE hiện có của encodeInto trong tệp đó làm mẫu, và kiểm tra xem đầu ra stream dựa trên encodeUtf8Chunk hoặc bytes() có cần cùng thay đổi hay không. Hoàn thành khi repro trong issue biên dịch được ở strict mode với @cloudflare/workers-types và các bài kiểm tra kiểu đều đạt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
In @cloudflare/workers-types 5.20261121.1, TextEncoder declares:
encode(input?: string): Uint8Array;
Since TypeScript 5.7 made typed arrays generic over their buffer, a bare Uint8Array means Uint8Array<ArrayBufferLike>, which includes SharedArrayBuffer. encode always returns a view over a fresh, non-shared ArrayBuffer, so the precise type is Uint8Array<ArrayBuffer>. TypeScript's own lib.dom.d.ts and lib.webworker.d.ts (5.9) declare encode(input?: string): Uint8Array<ArrayBuffer>, and @types/node declares NodeJS.NonSharedUint8Array.
Repro
TypeScript 7.0.2, @cloudflare/workers-types 5.20261121.1, "types": ["@cloudflare/workers-types"], "strict": true:
export function encode(value: string): Uint8Array<ArrayBuffer> {
return new TextEncoder().encode(value);
}
error TS2322: Type 'Uint8Array<ArrayBufferLike>' is not assignable to type 'Uint8Array<ArrayBuffer>'.
Type 'ArrayBufferLike' is not assignable to type 'ArrayBuffer'.
Type 'SharedArrayBuffer' is not assignable to type 'ArrayBuffer'.
Why it matters
Code that runs on both Node and Workers has to type the result as Uint8Array<ArrayBuffer>, because Node's and lib.dom's BufferSource reject ArrayBufferLike-backed views. With workers-types loaded, the same code then needs a cast or a Uint8Array.from(...) copy.
Request
Declare encode(input?: string): Uint8Array<ArrayBuffer> (for example with a JSG_TS_OVERRIDE in src/workerd/api/encoding.h, as encodeInto already has). Other APIs that return freshly allocated buffers, such as encodeUtf8Chunk-backed streams or bytes(), may have the same widening.
Related: #7833 tracks rejecting SharedArrayBuffer-backed views at runtime in SubtleCrypto. That issue is about runtime behaviour; this one is only about the declared return type.
- Ngôn ngữ chính
- C++
- Star
- 9.3k
- Fork
- 845
- Merge trung bình
- 1 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 558
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc 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 cloudflare/workerd
-
Build fails on macOS 27: dyld refuses stripped Rust proc-macros (mis-aligned LINKEDIT string pool)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
cloudflare/workerd#8963 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
D1 export: `quote()` in d1.js turns a literal `\n` into a newline when the value also has a real newlineCó thể đã có người làm @Jeremiah-D đã nhận 8 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
cloudflare/workerd#8678 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
cloudflare/workerd#8575 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix(types): ForwardableEmailMessage omits the documented canBeForwarded propertyCó thể đã có người làm @itsrayeedscodespace đã nhận 19 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
cloudflare/workerd#8290 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Streaming TextDecoder drops U+FEFF at the start of a chunk that follows an ASCII-only chunkCó thể làm lại được @oliarmak-web đã nhận 19 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
cloudflare/workerd#8279 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của cloudflare/workerd
Issue tương tự
-
Android Bug Core Drape
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
organicmaps/organicmaps#14449 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
comp-codecs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
ClickHouse/ClickHouse#135159 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
difficulty:easy func:python os:windows prio:high type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NatronGitHub/Natron#2029 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
ardazishvili/Sota#114 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`Rect::containsPoint` is not `const`, so a `const Rect` cannot be asked whether it holds a pointĐang mởNeeds: Triage :mag:
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
react/react-native#60349 ·
Maintainer thường phản hồi trong vòng 1 ngày