microsoft / microsoft/TypeScript
Cannot assign Uint8Array type to Uint8Array variable created with constructor
Offen
@sandersn arbeitet bereits daran.
Seit 04.6.2025.
Needs Investigation
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
🔎 Search Terms
uint8array
🕗 Version & Regression Information
- This changed between versions 5.7.3 and 5.6.3
- This changed in commit or PR #59417
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Uint8Arrays
- I was unable to test this on prior versions because Uint8Array was not generic before 5.7.3
⏯ Playground Link
💻 Code
function getArr (): Uint8Array {
return new Uint8Array(0)
}
let arr = new Uint8Array(0)
arr = getArr() // fails compilation with TS2322
let arr2: Uint8Array = new Uint8Array(0)
arr2 = getArr() // this is fine
🙁 Actual behavior
TS2322 is thrown during compilation.
🙂 Expected behavior
I should be able to assign a value of type Uint8Array to a variable initialised with the Uint8Array constructor without specifying extra generics or types.
Additional information about the issue
The compilation error is:
Type 'Uint8Array<ArrayBufferLike>' is not assignable to type 'Uint8Array<ArrayBuffer>'.
Type 'ArrayBufferLike' is not assignable to type 'ArrayBuffer'.
Type 'SharedArrayBuffer' is missing the following properties from type 'ArrayBuffer': resizable, resize, detached, transfer, transferToFixedLength(2322)
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.