Property 'name' does not exist on type 'Blob'

Viewed 2789

I have a blob (naming it file) and I am trying to store its name value by doing something like this

properties.name = file.name;

but it's keep complaining about

Property 'name' does not exist on type 'Blob'.

The quick fix they suggested adds name to blob in TypeScript node_modules folder which I don't want to.

What are the suggestion/options I should do to fix this error? Sorry, I am new to TS and I am not sure what to search.

This is my image blob console.log. It could be possible (from comment) that library I am using might have added blob

lastModified: 1596803874299
lastModifiedDate: Fri Aug 07 2020 18:07:54 GMT+0530 (India Standard Time) {}
name: "photo of Elizabeth Tower, London-gcffb6skhv.jpg"
size: 408146
type: "image/jpeg"
webkitRelativePath: ""
2 Answers

I know that this is a 1 year and 7 months old question, but just ran into this issue myself.

The solution here is to use the type File that extends Blob.

A Blob can be of the File type. In this context you will want to use a File type.

A File object is a specific kind of Blob, and can be used in any context that a Blob can.

A File object contains the name property you are looking for.

Example interface:

interface FormValues {
  title: string;
  description: string;
  file: File | null; // See the File type here
}
Related