类型'SharedArrayBuffer'不能分配给'ArrayBuffer'类型

问题描述 投票:5回答:1

我已将我的应用程序从角度4升级到角度6.我收到以下错误。错误发生在行返回data.buffer。这是兼容性问题吗?

error TS2322: Type 'ArrayBuffer | SharedArrayBuffer' is not assignable to type 'Arr
ayBuffer'.
  Type 'SharedArrayBuffer' is not assignable to type 'ArrayBuffer'.
    Types of property '[Symbol.toStringTag]' are incompatible.
      Type '"SharedArrayBuffer"' is not assignable to type '"ArrayBuffer"'.

serialize(): ArrayBuffer {
        let source: ArrayLike<number>[] = this.contents.map(o => new Uint8Array(o));
        let lengths = source.map(o => this.numToArr(o.length));
        if (!!this.value) {
            const bytes = utf8.toByteArray(JSON.stringify(this.value, null, null));
            const dataLength = this.numToArr(bytes.length);
            source = [bytes, ...source];
            lengths = [dataLength, ...lengths];
        }

        const totalLength = source.reduce((acc, o) => acc + o.length, 0) + lengths.reduce((acc, o) => acc + o.length, 0);

        const data = new Uint8Array(totalLength);
        let offset = 0;
        source.forEach((item, index) => {
            const prefix = lengths[index];
            data.set(prefix, offset);
            offset += prefix.length;
            data.set(item, offset);
            offset += item.length;
        });

        return data.buffer;
    }
angular
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.