microsoft / microsoft/TypeScript

Revert ts5.9 changes for Uint8Array

オープン
#62,240 コメント 39 件 リアクション 19 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Docs
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

⚙ Compilation target

es2022

⚙ Library

es2022, dom

Missing / Incorrect Definition
  1. User sees weird error. "Uint16Array is not assignable to Uint16Array". First thoughts: WTF? What does this even mean? "But I don't use SharedArrayBuffer in my project!!"
TS2345: Argument of type 'Uint16Array' is not assignable to parameter of type 'Uint16Array<ArrayBuffer>'.
  Type 'ArrayBufferLike' is not assignable to type 'ArrayBuffer'.
    Type 'SharedArrayBuffer' is not assignable to type 'ArrayBuffer'.
      Types of property '[Symbol.toStringTag]' are incompatible.
        Type '"SharedArrayBuffer"' is not assignable to type '"ArrayBuffer"'.
  1. User heads to blog post and sees "explicitly writing out Uint8Array<ArrayBuffer> rather than a plain Uint8Array"
  2. User applies the changes.
  3. The changes make library unusable in TS <=5.6.
  4. User reverts to older TS to ensure his library doesn't require "latest ts".
  5. There is zero other documentation about resolving the problem, so it's unclear how to solve it. It's also not obvious that () => new Uint8Array, () => Uint8Array.from([]) and () => Uint8Array.of() now all return subtyped uint8array, which fails in TS <=5.6

Previous issue text

ts5.7 change which made uint8arrays generic was okay.

ts5.9 introduced absolutely horrific change which breaks Uint8Array-heavy projects.

It seems like some changes made types too strict. It's unclear at which phase - perhaps during inference (i'm using infer). I'm now constantly getting those errors and it's really unhelpful - it's unclear what to do. Blog post recommendations (https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-9.html#libdts-changes) make arrays subtype-specific. It seems like this is a wrong way to fix things. Users should not be forced to always consume ArrayBuffer-based type arrays. It's perfectly fine to use either ArrayBuffer or SharedArrayBuffer based arrays, the changes are minor. The defaults should be able to consume both types!

// type Poly = Uint16Array
TS2345: Argument of type 'Poly' is not assignable to parameter of type 'Uint16Array<ArrayBuffer>'.
  Type 'ArrayBufferLike' is not assignable to type 'ArrayBuffer'.
    Type 'SharedArrayBuffer' is not assignable to type 'ArrayBuffer'.
      Types of property '[Symbol.toStringTag]' are incompatible.
        Type '"SharedArrayBuffer"' is not assignable to type '"ArrayBuffer"'.
Sample Code

I've spent a lot of time but was not able to produce a standalone example which reproduces the issue. There are a bunch of types at play and it's unclear which exact type causes the issue.

The code which produces errors is in commit cb76058 of https://github.com/paulmillr/noble-post-quantum

git clone https://github.com/paulmillr/noble-post-quantum
cd noble-post-quantum
git checkout cb76058
npm install
npm run build

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされたリリースノートに記載されている TypeScript 5.9 lib.d.ts の変更から始め、次に noble-post-quantum のコミット cb76058 とその npm run build コマンドを使って報告された失敗を再現します。TypeScript の各バージョン間で Uint8Array の動作を比較し、影響を受ける定義が新しいバージョンと古いサポート対象バージョンの両方で引き続き使用できれば完了とします。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。