1

I'm coding Nuxt 3 and having the following bug

my function,

const checkFileSize = (file: File): boolean => {
  if (!file) {
    return true;
  }

  return props.maxSize * 1024 * 1024 >= file.size;
};

This function is call when I upload a file.

but when I console log the above file it returns a Proxy object and because of that I can not read file.size . The file.size return undefined

I fixed it into file.value.size and it worked but the type error on the function input is wrong (because interface File does not have any value key)

So do I have to change the type (In this case File => what?).
Or do I have to call my function somewhere else to get the exactly file: File input

I fixed it into file.value.size and it worked but the type error on the function input is wrong (Cuz interface File does not have any value key)

*Updated:

Currently I use this code to call handleChange function, and inside handleChange I call checkFileSize

const handleChange = (file: File) => {
     checkFileSize(file)
}

<v-file-input @change="handleChange" />

Still the problem of define a type for ref value

6
  • Try changing your file param type to ref<File> Commented Nov 17, 2022 at 7:08
  • it got errors ['ref' refers to a value, but is being used as a type here. Did you mean 'typeof ref'?ts(2749) ] Commented Nov 17, 2022 at 7:42
  • Is this helpful?: stackoverflow.com/a/59389885/12962668 Commented Nov 17, 2022 at 8:17
  • The question lacks the details. It's not because it's a proxy, it's because it's a ref. If you expect File then you could pass ref value to it and not a ref itself. Commented Nov 17, 2022 at 8:19
  • const handleChange = (file: File) => {} Seems that the handleChange method has a refs input, and I dont know how to declare the type of a refs Commented Nov 18, 2022 at 0:29

1 Answer 1

0

it got errors ['ref' refers to a value, but is being used as a type here.

Use Ref to fix type error:

const checkFileSize = (file: Ref<File>): boolean => {
  if (!file.value) {
    return true;
  }

  return props.maxSize * 1024 * 1024 >= file.value.size;
};
Sign up to request clarification or add additional context in comments.

Comments

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.