I have upgraded my application from angular 4 to angular 6. I am getting the following error. The error is at the line return data.buffer. Is this a es compatibility issue ?
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"'.
code
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;
}
Either use appropriate type castings as below:
return data.buffer as ArrayBuffer;
Or Define a variable that can accept either an ArrayBuffer or a SharedArrayBuffer, as below:
pdf: ArrayBuffer | SharedArrayBuffer;
...
...
this.pdf = data.buffer;
return this.pdf;
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With