validate.js icon indicating copy to clipboard operation
validate.js copied to clipboard

Typescript Error

Open paulogr opened this issue 8 years ago • 2 comments

I'm getting this error when trying to call the validate function

validate_js_1.default is not a function

I'm importing the lib like this

import validate from 'validate.js'

and calling it this way

validate({}, constraints)

What am I doing wrong?

I'm using typescript 2.5

Thank you!

paulogr avatar Sep 18 '17 23:09 paulogr

you need to import like this import * as validate from 'validate.js';.

You might need to cast validate to any before you use it like:

let formValues = (<any>validate).collectFormValues(form);
let validationResult = (<any>validate)(formValues, constraints);

roly445 avatar Sep 25 '17 11:09 roly445

That doesn't seem very nice. I don't use typescript so I'm not really sure how to solve it.

ansman avatar Nov 12 '17 04:11 ansman