issue: "Illegal constructor" error when using the classValidatorResolver with a file input
See original GitHub issueVersion Number
7.15.4
Codesandbox/Expo snack
https://codesandbox.io/s/flamboyant-breeze-trm2p?file=/src/App.tsx
Steps to reproduce
- Create a simple form with a file input e.g.
<input type="file" {...register('test')} />
- Create a class for the validation schema e.g.
class ValidationSchema {
test: any;
}
- Give the validation class to the useForm hook e.g.
useForm< ValidationSchema >({ resolver: classValidatorResolver(ValidationSchema), });
- Submit the form after selecting a .jpg file. You will see a “Illegal constructor” error
Expected behaviour
We shouldn’t get an error.
What browsers are you seeing the problem on?
Chrome, Safari
Relevant log output
Unhandled Runtime Error
TypeError: Illegal constructor
Code of Conduct
- I agree to follow this project’s Code of Conduct
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (6 by maintainers)
Top Results From Across the Web
TypeError: Illegal constructor when trying to create a new ...
If I now want to instantiate a ui component (defined and imported in /src/index.js) in view-matrix.js, I'm getting the following error. 1) ...
Read more >Uncaught TypeError: Illegal constructor Error #1181 - GitHub
Hi, I am getting this error: Uncaught TypeError: Illegal constructor at n (prism.js:1) at prism.js:1 at prism.js:1 at Array.
Read more >true` results in `Uncaught TypeError: Illegal constructor` - Reddit
I am trying to get my app to work as a web component. However, I keep getting this error: Uncaught TypeError: Illegal constructor....
Read more >How to solve "Uncaught TypeError: Illegal constructor"
The Illegal constructor error is thrown when a class extends HTMLElement, but is instantiated like a regular class. Using classes that inherits from ......
Read more >390457 - Please implement a FileList constructor - Monorail
since we can't add or remove files from a FileList in <input type=file> the only way to ... it throws a TypeError: Illegal...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for this but it appears your solution doesn’t work in the sandbox provided. I get the error “Not enough arguments”
It works with the @williamdespard 's custom resolver because he is using
Object.assign
, we can’t use it in our case. It’s not compatible with nested data.I’ve found a possible solution, I’m a beginner with
class-validator
, you may adapt the code below:👉🏻 https://codesandbox.io/s/restless-wood-mw9mz