编译后,会生成上述错误消息。这是我的mime-type.validator.ts
文件。
import { AbstractControl } from '@angular/forms';
import { Observable, Observer, of } from 'rxjs';
export const mimeType = (
control: AbstractControl
): Promise<{ [key: string]: any }> | Observable<{ [key: string]: any }> => {
if (typeof(control.value) === 'string') {
return of(null);
}
const file = control.value as File;
const fileReader = new FileReader();
const frObs = Observable.create(
(observer: Observer<{ [key: string]: any }>) => {
fileReader.addEventListener('loadend', () => {
const arr = new Uint8Array(fileReader.result).subarray(0, 4);
let header = '';
let isValid = false;
for (let i = 0; i < arr.length; i++) {
header += arr[i].toString(16);
}
switch (header) {
...
}
if (isValid) {
observer.next(null);
} else {
observer.next({ invalidMimeType: true });
}
observer.complete();
});
fileReader.readAsArrayBuffer(file);
}
);
return frObs;
};
我如何摆脱“类型”字符串不能分配给“ ArrayBuffer | SharedArrayBuffer | ArrayLike'。错误消息...谢谢!
答案 0 :(得分:0)
您可以尝试以下操作:
const arr = new Uint8Array(fileReader.result as ArrayBuffer).subarray(0,4);