v8n icon indicating copy to clipboard operation
v8n copied to clipboard

How to properly extend with typescript?

Open AngeloTadeucci opened this issue 2 years ago • 0 comments

Example snippet:

function validEmail() {
  return (email: string) => {
    const re =
      /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(String(email).toLowerCase());
  };
}

v8n.extend({
  validEmail,
});

v8n().validEmail().test("angelo@email"); // error here on 'validEmail'

The extend functionality works fine but when building, for example with Next, it'll throw an error like: Type error: Property 'validEmail' does not exist on type 'V8nValidator'.

Thanks! :D

AngeloTadeucci avatar Aug 11 '22 17:08 AngeloTadeucci