Jasmine unit test for file size with TypeScript in Angular

You can use Object.defineProperty to overwrite the size property.

/** Creates a "1TB" file given the file name. */
function getHugeFile(name: string) : File {
  const file = new File([''], name);
  Object.defineProperty(
      file, 'size', {value: Math.pow(1024, 4), writable: false});
  return file;
}

If you wanted to resolve the TS error, here is the ways,

interface IFile extends File {
    size: number;
}

const file: IFile = new File([''], 'filename', { type: 'image/png' });
file.size = 8242880; // Works..