`TextEncoder.encode` is typed `Uint8Array<ArrayBufferLike>` in workers-types; it returns a non-shared buffer
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 72/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- cpp, typescript
- 領域
- api
調査の方向性
変更すべき宣言は TextEncoder.encode で、その型は src/workerd/api/encoding.h の C++ バインディングから生成されています。同ファイルにある既存の encodeInto の JSG_TS_OVERRIDE をパターンとして使い、encodeUtf8Chunk に基づくストリーム出力や bytes() も同じ変更が必要かを確認してください。issue の再現コードが @cloudflare/workers-types を使い strict mode でコンパイルでき、型テストが通れば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- C++
- スター
- 9.3k
- フォーク
- 845
- 平均マージ
- 1日 23時間
- マージ済み PR(30日)
- 558
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
cloudflare/workerd のほかの issue
-
Build fails on macOS 27: dyld refuses stripped Rust proc-macros (mis-aligned LINKEDIT string pool)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
cloudflare/workerd#8963 ·
メンテナーはふだん 1 日以内に返信
-
D1 export: `quote()` in d1.js turns a literal `\n` into a newline when the value also has a real newline対応中かも @Jeremiah-D が 8 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
cloudflare/workerd#8678 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
cloudflare/workerd#8575 ·
メンテナーはふだん 1 日以内に返信
-
fix(types): ForwardableEmailMessage omits the documented canBeForwarded property対応中かも @itsrayeedscodespace が 19 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
cloudflare/workerd#8290 ·
メンテナーはふだん 1 日以内に返信
-
Streaming TextDecoder drops U+FEFF at the start of a chunk that follows an ASCII-only chunk再び着手できるかも @oliarmak-web が 19 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
cloudflare/workerd#8279 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
cloudflare/workerd の issue をすべて見る
似ている issue
-
Android Bug Core Drape
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
organicmaps/organicmaps#14449 ·
メンテナーはふだん 1 日以内に返信
-
comp-codecs
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
ClickHouse/ClickHouse#135159 ·
メンテナーはふだん 1 日以内に返信
-
difficulty:easy func:python os:windows prio:high type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
NatronGitHub/Natron#2029 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
ardazishvili/Sota#114 ·
メンテナーはふだん 1 日以内に返信
-
`Rect::containsPoint` is not `const`, so a `const Rect` cannot be asked whether it holds a pointオープンNeeds: Triage :mag:
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
react/react-native#60349 ·
メンテナーはふだん 1 日以内に返信