加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 类型’SharedArrayBuffer’不能分配给’ArrayBuffer

发布时间:2020-12-17 18:07:10 所属栏目:安全 来源:网络整理
导读:我已将我的应用程序从角度4升级到角度6.我收到以下错误.错误发生在行返回data.buffer.这是兼容性问题吗? error TS2322: Type 'ArrayBuffer | SharedArrayBuffer' is not assignable to type 'ArrayBuffer'. Type 'SharedArrayBuffer' is not assignable to
我已将我的应用程序从角度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,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;
    }

解决方法

使用适当的类型铸件如下:

return data.buffer as ArrayBuffer;

或者定义一个可以接受ArrayBuffer或SharedArrayBuffer的变量,如下所示:

pdf: ArrayBuffer | SharedArrayBuffer;
...

...
this.pdf = data.buffer;
return this.pdf;

希望这可以帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读