#how to type fileList and use in useState()

9 messages · Page 1 of 1 (latest)

fathom vigil
#

my upload returns a fileList. I created an interface fileList and use it in useState to store the uploaded fileList.

`
Hello! I am really stuck for too long at this TS issue and would very much appreciate any hint :
my upload returns a fileList. I created an interface fileList and use it in useState to store the uploaded

interface FileList {
readonly length: number;
item(index: number): File | null;
[index: number]: File;
[Symbol.iterator](): IterableIterator<File>;
}````

const [fileList, setFileList] = useState<FileList | null>(null);

in the onChangeHandler on the input field, I set
`setFileList(files)`
and then get the following TS error:

`Argument of type '{}' is not assignable to parameter of type 'SetStateAction<FileList | null>'.ts(2345)
(parameter) files: {}`



what should I change in the Type declaration?
sudden sigil
#

There should already be a FileList.

#

So you don't need to create your own.

fathom vigil
#

thank you for answering 🙂 and: oh, yes, now I see that it works the same without my declaration. But I still get the same error, do you know what I could do?

sudden sigil
#

Show your handler code.

#

If you can, make a reproduction on TS playground.

fathom vigil
#

Hi @sudden sigil , I entered the code into this codesandbox, mmh, I know, it looks a bit messy.. the upload component is from a component library.

#

argh, didn't work, will check why

fathom vigil
#

apart from codesandbox not working for me, the issue is that I am using an upload component from a library. So I don't have the code of the onChangeHandler().