From 7b574e764b4b9065308c6b98d948a7e3e16fa19a Mon Sep 17 00:00:00 2001 From: Dominik Broj <19861998+thetric@users.noreply.github.com> Date: Tue, 24 Sep 2019 10:12:16 +0200 Subject: [PATCH] docs(readme): add usage notes for TypeScript users --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index d645c3f70..845481207 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,11 @@ Try it in the Node.js REPL: https://tonicdev.com/npm/ajv The fastest validation call: ```javascript +// Node.js require: var Ajv = require('ajv'); +// or ESM/TypeScript import +import Ajv from 'ajv'; + var ajv = new Ajv(); // options can be passed, e.g. {allErrors: true} var validate = ajv.compile(schema); var valid = validate(data); @@ -165,6 +169,10 @@ The best performance is achieved when using compiled functions returned by `comp __Please note__: every time a validation function or `ajv.validate` are called `errors` property is overwritten. You need to copy `errors` array reference to another variable if you want to use it later (e.g., in the callback). See [Validation errors](#validation-errors) +__Note for TypeScript users__: `ajv` provides its own TypeScript declarations +out of the box, so you don't need to install the deprecated `@types/ajv` +module. + ## Using in browser