microsoft / microsoft/TypeScript

Cannot assign Uint8Array type to Uint8Array variable created with constructor

Đang mở
#61,793 6 bình luận 1 reaction 1 người được giao Xem trên GitHub

@sandersn đang làm issue này rồi.

Từ ngày 4/6/2025.

Needs Investigation
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

🔎 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

https://www.typescriptlang.org/play/?target=11&ts=5.8.3#code/GYVwdgxgLglg9mABAcwKZQIICcuIBQCUAXIgKoxhQAc2WAhgJ6IDeAUIoluiFkmKgHcyFarUZ4ADAVYBfVqwA26RHRyIAvIn5DylGjnFTWq3JrSYcheUqgqcAJhK7RBppu3C9YhpOkn7GijotFZAA

💻 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)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.