microsoft / microsoft/TypeScript

Revert ts5.9 changes for Uint8Array

Offen
#62,240 39 Kommentare 19 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Docs
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

⚙ 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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit den in den verlinkten Release Notes beschriebenen Änderungen an TypeScript 5.9 lib.d.ts und reproduziere anschließend den gemeldeten Fehler mit Commit cb76058 von noble-post-quantum und dessen npm run build-Befehl. Vergleiche das Verhalten von Uint8Array über verschiedene TypeScript-Versionen hinweg. Als abgeschlossen gilt die Aufgabe, wenn die betroffenen Definitionen sowohl für neuere als auch für ältere unterstützte TypeScript-Versionen verwendbar bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.