1

When it is compiled it generates the above error message.This is my mime-type.validator.ts file.

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;
    };

how can I get rid of the 'Type 'string' is not assignable to type 'ArrayBuffer | SharedArrayBuffer | ArrayLike'.' error message ...thank you!

1

1 Answer 1

3

You can try something like this:

const arr = new Uint8Array(fileReader.result as ArrayBuffer).subarray(0,4);
Sign up to request clarification or add additional context in comments.

1 Comment

Welcome to SO. It's a good idea to add some explanation to your answer so users can make use of it more readily.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.